Beispiel #1
0
	def line_hollow(self,search_result,y_legend,line_text):
		#定义chart
		chart = openFlashChart.template(u'折线图')
		chart.set_y_legend(y_legend, style = '{font-size: 12px}')#设置y轴
		#横坐标
		x_labels = []
		for row in search_result:
			x_labels.append(row[0])
		chart.set_x_axis(colour = '#736AFF', three_d = 5, labels = x_axis_labels(labels = x_labels))

		row_num = len(search_result)#共多少条记录
		column_num = len(search_result[0])#每条记录有几列
		#取值
		mymax = 0
		
		for column_i in range(1,column_num):
			plot = Line()
			values = []
			for row in search_result:
				if int(row[column_i]) > mymax:
					mymax = int(row[column_i])
				values.append(int(row[column_i]))
			plot.set_values(values=values)
			plot.set_colour(colorArr[column_i-1])
			plot['on-show'] = dict([['type','shrink-in'],['cascade',1],['delay',0.5]])#api中没有on-show 手动加上
			plot['dot-style'] = dict([['type','star'],['colour','#a44a80'],['dot-size',5]])#api中没有dot-style 手动加上
			plot['text'] = line_text[column_i-1]
			chart.add_element(plot)
			values = []
		chart.set_y_axis(min = 0, max = mymax)
		return chart.encode()
Beispiel #2
0
    def line_hollow(self, search_result, y_legend, line_text):
        #定义chart
        chart = openFlashChart.template(u'折线图')
        chart.set_y_legend(y_legend, style='{font-size: 12px}')  #设置y轴
        #横坐标
        x_labels = []
        for row in search_result:
            x_labels.append(row[0])
        chart.set_x_axis(colour='#736AFF',
                         three_d=5,
                         labels=x_axis_labels(labels=x_labels))

        row_num = len(search_result)  #共多少条记录
        column_num = len(search_result[0])  #每条记录有几列
        #取值
        mymax = 0

        for column_i in range(1, column_num):
            plot = Line()
            values = []
            for row in search_result:
                if int(row[column_i]) > mymax:
                    mymax = int(row[column_i])
                values.append(int(row[column_i]))
            plot.set_values(values=values)
            plot.set_colour(colorArr[column_i - 1])
            plot['on-show'] = dict([['type', 'shrink-in'], ['cascade', 1],
                                    ['delay', 0.5]])  #api中没有on-show 手动加上
            plot['dot-style'] = dict([['type', 'star'], ['colour', '#a44a80'],
                                      ['dot-size', 5]])  #api中没有dot-style 手动加上
            plot['text'] = line_text[column_i - 1]
            chart.add_element(plot)
            values = []
        chart.set_y_axis(min=0, max=mymax)
        return chart.encode()
Beispiel #3
0
def data(request, xen_id):
    from random import randint

    print "chamado para o id", xen_id
    xenHost = XenHost.objects.filter(id=xen_id)[0]

    data = "{ elements : ["

        # Obtem na base estatisticas por host
    querySetByHost = XenHostStatistic.objects.filter(xenHost=xenHost)
    #querySetByHostAndTime = querySetByHost.filter(date__range=(horaLimite, horaAtual))
    virtualMachinesStatistics = querySetByHost.order_by('-date')[:10]
    values = []
    x_max = 0

    data = data + "type: 'line', values: ["
    hora_referencia = timegm(virtualMachinesStatistics[len(virtualMachinesStatistics)-1].date.timetuple())
    for guestStat in virtualMachinesStatistics:
        #vm_guest = VirtualMachine(realMachine=host, vm_id=guestStat['vm_id'], weight=guestStat['cpu_average'])
        y = guestStat.cpu
        x = timegm(guestStat.date.timetuple())-hora_referencia
        values.append(value((y)))
        if x > x_max:
            x_max = x

    data = data + "], title : { text: 'Three lines example' }, y_axis: { min: 0, max: 20, steps: 5 }}"
    plot = Line(colour = '#FFD600', values = values)
    plot.set_dot_size(3)

    chart = openFlashChart.template(str(xenHost.name))
    #chart.set_x_axis(min = 0, max = x_max, steps=x_max/10)
    chart.set_y_axis(min = 0, max = 100, steps=10)
    
    chart.add_element(plot)

    return HttpResponse(chart.encode())
Beispiel #4
0
    def line(self):
        plot1 = Line(text="line1", fontsize=20, values=range(0, 10))
        plot2 = Line(text="line2", fontsize=06, values=range(10, 0, -1))
        plot3 = Line(text="line3", fontsize=12, values=range(-5, 5))

        plot1.set_line_style(4, 3)
        plot2.set_line_style(5, 5)
        plot3.set_line_style(4, 8)

        plot1.set_colour('#D4C345')
        plot2.set_colour('#C95653')
        plot3.set_colour('#8084FF')

        chart = openFlashChart.template("Line chart")
        chart.set_y_axis(min=-6, max=10)

        chart.add_element(plot1)
        chart.add_element(plot2)
        chart.add_element(plot3)

        return chart.encode()
Beispiel #5
0
    def ajax(self, count):
        if int(count) % 3 is 0:
            plot = Line_Dot(text="line1",
                            fontsize=20,
                            values=[
                                None, 5,
                                dot_value(1, '#D02020', '#val#<br>Text'), 2, 4,
                                None, None, 2, 7, 5
                            ])
        elif int(count) % 3 is 1:
            plot = Line(text="line2", fontsize=12, values=range(-4, 7, 1))
        else:
            plot = Bar_Glass(
                text="bar1",
                values=[
                    4, None, -4, 3,
                    bar_glass_value(
                        (5, -2), '#333333',
                        'Special:<br>Top = #top#<br>Bottom = #bottom#'), 7,
                    None, None, -5, 5
                ])

        plot.set_tooltip('Title1:<br>Amount = #val#')
        plot.set_on_click('plot1')
        plot.set_line_style(4, 3)

        plot.set_colour('#D4C345')

        chart = openFlashChart.template(
            "Testing chart: %s" % count,
            style=
            '{font-size: 40px; font-family: Times New Roman; color: #A2ACBA; text-align: right;}'
        )

        chart.set_x_axis(stroke=10,
                         colour='#165132',
                         tick_height=30,
                         grid_colour='#AAEE00',
                         offset=True,
                         steps=2,
                         labels=x_axis_labels(
                             labels=list('sfwertr56w') +
                             [x_axis_label('custom!!', '#2683CF', 24, 210)],
                             steps=2))
        chart.set_y_axis(stroke=5,
                         colour='#1E33FF',
                         tick_length=15,
                         grid_colour='#090305',
                         offset=True,
                         steps=4,
                         min=-6)
        chart.set_y_axis_right(stroke=5,
                               colour='#44FF22',
                               tick_length=20,
                               grid_colour='#55ff55',
                               offset=True,
                               steps=1)

        chart.set_x_legend("x-axis legend",
                           style='{font-size: 20px; color: #778877}')
        chart.set_y_legend("y-axis legend",
                           style='{font-size: 22px; color: #778877}')

        chart.set_tooltip(
            shadow=True,
            stroke=4,
            colour='#909090',
            bg_colour='#FAFAFA',
            title_style='{font-size: 14px; color: #CC2A43;}',
            body_style='{font-size: 10px; font-weight: bold; color: #000000;}')

        chart.add_element(plot)

        return chart.encode()
Beispiel #6
0
	def line(self):
		plot1 = Line(text = "line1", fontsize = 20, values = range(0,10))
		plot2 = Line(text = "line2", fontsize = 06, values = range(10,0, -1))
		plot3 = Line(text = "line3", fontsize = 12, values = range(-5,5))
		
		plot1.set_line_style(4, 3)
		plot2.set_line_style(5, 5)
		plot3.set_line_style(4, 8)
		
		plot1.set_colour('#D4C345')
		plot2.set_colour('#C95653')
		plot3.set_colour('#8084FF')
		
		chart = openFlashChart.template("Line chart")
		chart.set_y_axis(min = -6, max = 10)
		
		chart.add_element(plot1)
		chart.add_element(plot2)
		chart.add_element(plot3)

		return chart.encode()
Beispiel #7
0
	def test(self):
		plot1 = Line(text = "line1", fontsize = 20, values = [None, 5, 1, 2, 4, None, None, 2, 7, 5])
		plot2 = Line(text = "line2", fontsize = 12, values = range(-4, 7, 1))
		plot3 = Bar_Glass(text = "bar1", values = [4, None, -4, 3, bar_glass_value((5, -2), '#333333', 'Special:<br>Top = #top#<br>Bottom = #bottom#'), 7, None, None, -5, 5])
				
		plot1.set_tooltip('Title1:<br>Amount = #val#')
		plot2.set_tooltip('Title2:<br>Value = #val#')
		plot3.set_tooltip('Title3:<br>Height = #val#')
		
		plot1.set_on_click('plot1')
		plot2.set_on_click('plot2')
		
		plot1.set_line_style(4, 3)
		plot2.set_line_style(4, 8)
		
		plot1.set_colour('#D4C345')
		plot2.set_colour('#8084FF')
		plot3.set_colour('#FF84FF')
		
		chart = openFlashChart.template("Testing chart", style = '{font-size: 40px; font-family: Times New Roman; color: #A2ACBA; text-align: right;}')

		chart.set_x_axis(stroke = 10, colour = '#165132', tick_height = 30, grid_colour = '#AAEE00', offset = True, steps = 2, labels = x_axis_labels(labels = list('sfwertr56w') + [x_axis_label('custom!!', '#2683CF', 24, 'diagonal')], steps = 2))
		chart.set_y_axis(stroke = 5, colour = '#1E33FF', tick_length = 15, grid_colour = '#090305', offset = True, steps = 4, min = -6)
		chart.set_y_axis_right(stroke = 5, colour = '#44FF22', tick_length = 20, grid_colour = '#55ff55', offset = True, steps = 1)

		chart.set_x_legend("x-axis legend", style = '{font-size: 20px; color: #778877}')
		chart.set_y_legend("y-axis legend", style = '{font-size: 22px; color: #778877}')

		chart.set_tooltip(shadow = True, stroke = 4, colour = '#909090', bg_colour = '#FAFAFA', title_style = '{font-size: 14px; color: #CC2A43;}', body_style = '{font-size: 10px; font-weight: bold; color: #000000;}')
		
		chart.add_element(plot1)
		chart.add_element(plot2)
		chart.add_element(plot3)

		return chart.encode()
Beispiel #8
0
def get_chart(request,style,date_start,date_end):
    raw_data = get_chart_vars(request,date_start,date_end)
    var1 = []
    var2 = []
    dates = []
    if raw_data['variable1'] != None:
        var_legend = raw_data['variable1_name']
        for items in raw_data['variable1']:
            var1.append(int(items[1]))
            dates.append(str(items[0]))
    if raw_data['variable2'] != None:
        var_legend = raw_data['variable2_name']
        for items in raw_data['variable2']:
            var2.append(int(items[1]))	
    chart = openFlashChart.template('')
    chart.set_bg_colour(colour='#ffffff')
    if len(var1) > 0:
        range_y1_min = round(min(var1)*0.95,0)
        range_y1_max = round(max(var1)*1.05,0)
        range_y1_steps = round(round(max(var1)*1.05,0)/10,0)
    else:
        range_y1_min = 0
        range_y1_max = 0
        range_y1_steps = 0
    if len(var2) > 0:
        range_y2_min = round(min(var2)*0.95,0)
        range_y2_max = round(max(var2)*1.05,0)
        range_y2_steps = round(round(max(var2)*1.05,0)/10,0)
    else:
        range_y2_min = 0
        range_y2_max = 0
        range_y2_steps = 0
    chart.set_y_axis(min = range_y1_min, max = range_y1_max, steps = range_y1_steps)
    chart.set_x_axis(labels = {'labels':dates, 'rotate':'vertical'})
    if style == 'lines':
        plot1 = Line(text = raw_data['variable1_name'], fontsize = 20, values = var1)
        plot2 = Line(text = raw_data['variable2_name'], fontsize = 20, values = var2)
        plot2['axis'] = "right"
        plot2.set_colour('#54b928')
        chart.set_y_axis_right(min = range_y2_min, max = range_y2_max, steps = range_y2_steps)
        if request.GET.get('onevar',None) == None:
            chart.add_element(plot2)
    elif style == 'pie':
        plot1 = Pie(text = raw_data['variable1_name'], fontsize = 20, values = var1, colours = ['#4f8dbc','#54b928'])
    elif style == 'columns':
        plot1 = Bar_Filled(text = raw_data['variable1_name'], fontsize = 20, values = var1)
        plot2 = Bar_Filled(text = raw_data['variable2_name'], fontsize = 20, values = var2)
        plot2['axis'] = "right"
        plot2.set_colour('#54b928')		
        chart.set_y_axis_right(min = range_y2_min, max = range_y2_max, steps = range_y2_steps)
        if request.GET.get('onevar',None) == None:
            chart.add_element(plot2)
    plot1.set_colour('#4f8dbc')
    chart.add_element(plot1)
    return HttpResponse(chart.encode())