def percent(): # The data for the bar chart data = [40, 15, 53.2] # The labels for the bar chart labels = ["8月5日", "8月6日", "8月7日"] # Create a XYChart object of size 250 x 250 pixels c = XYChart(600, 400) c.addTitle('解析统计', FONT, 14) # Set the plotarea at (30, 20) and of size 200 x 200 pixels c.setPlotArea(80, 40, 500, 320) # Add a bar chart layer using the given data layer = c.addBarLayer(data, COLOR) layer.setAggregateLabelStyle(FONT, 12) layer.setAggregateLabelFormat("{value}%") # Set the labels on the x axis. c.xAxis().setLabels(labels) # c.xAxis().setLabelStep(1, 1) c.xAxis().setLabelStyle(FONT, 12) c.yAxis().setLinearScale(0, 100, 20) c.yAxis().setLabelFormat("{value}%") # Output the chart c.makeChart("/temp/chart/percent.png") print 'done~'
def simple(): # The data for the bar chart data = [850000000, 150000000, 790000000, 210000000, 530000000, 310000000, 220000000] # The labels for the bar chart labels = ["8月5日", "8月6日", "8月7日", "8月8日", "8月9日", '8月10日', '8月11日'] # Create a XYChart object of size 250 x 250 pixels c = XYChart(600, 400) c.addTitle('解析统计', FONT, 14) # Set the plotarea at (30, 20) and of size 200 x 200 pixels c.setPlotArea(80, 40, 500, 320) # Add a bar chart layer using the given data layer = c.addBarLayer(data, COLOR) layer.setAggregateLabelStyle(FONT, 12) # Set the labels on the x axis. c.xAxis().setLabels(labels) c.xAxis().setLabelStep(2, 1) c.xAxis().setLabelStyle(FONT, 12) # Output the chart c.makeChart("/temp/chart/simple.png") print 'done~'
def bar_label(): # The data for the bar chart data = [85, 156, 179, 211, 123, 189, 166] # The labels for the bar chart labels = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] # Create a XYChart object of size 600 x 360 pixels c = XYChart(600, 360) # Set the plotarea at (70, 20) and of size 500 x 300 pixels, with transparent background and border # and light grey (0xcccccc) horizontal grid lines c.setPlotArea(70, 20, 500, 300, Transparent, -1, Transparent, 0xcccccc) # Set the x and y axis stems to transparent and the label font to 12pt Arial c.xAxis().setColors(Transparent) c.xAxis().setLabelStyle(FONT, 12) c.yAxis().setColors(Transparent) c.yAxis().setLabelStyle(FONT, 12) # Add a blue (0x6699bb) bar chart layer using the given data layer = c.addBarLayer(data, COLOR) # Use bar gradient lighting with the light intensity from 0.8 to 1.3 layer.setBorderColor(Transparent, barLighting(0.8, 1.3)) # Set rounded corners for bars # layer.setRoundedCorners() # Display labela on top of bars using 12pt Arial font layer.setAggregateLabelStyle(FONT, 12) # Set the labels on the x axis. c.xAxis().setLabels(labels) # For the automatic y-axis labels, set the minimum spacing to 40 pixels. c.yAxis().setTickDensity(40) # Add a title to the y axis using dark grey (0x555555) 14pt Arial Bold font c.yAxis().setTitle("Y-Axis Title Placeholder", FONT, 14, 0x555555) # Output the chart c.makeChart("/temp/chart/barlabel.png") print 'done~'
def create_multi_xychart(title, labels, series_list, series_top, maxv=100): # labels = [labels[0]] series_list = [series_list[0]] # Create a XYChart object of size 540 x 375 pixels c = XYChart(900, 320) # Add a title to the chart using 18 pts Times Bold Italic font #c.addTitle("Average Weekly Network Load", "timesbi.ttf", 18) title = c.addTitle(utils.to_utf8(title), "simsun.ttc", 12) title.setMargin2(20, 0, 5, 30) color_list = BASE_COLOR # Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical # gradient color from light red (ffdddd) to dark red (880000) as background. Set # border and grid lines to white (ffffff). chart_width = 30 + 190 * len(labels) c.setPlotArea(50, 90, chart_width, 200, c.linearGradientColor(60, 40, 60, 280, 0xffffff, 0xd8e2ec), -1, 0xffffff, 0xffffff) legendBox = c.addLegend(50, 16, 0, "simsun.ttc", 10) legendBox.setBackground(Transparent) #legendBox.setAlignment(TopCenter) legendBox.setHeight(30) # Set the x axis labels c.xAxis().setLabels([utils.to_utf8(label) for label in labels]) # Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5) # Set axis label style to 8pts Arial Bold c.xAxis().setLabelStyle("simsun.ttc", 9) c.yAxis().setLabelStyle("simsun.ttc", 9) # Set axis line width to 2 pixels c.xAxis().setWidth(2) c.yAxis().setWidth(2) c.yAxis2().setWidth(1) # Add axis title c.yAxis().setTitle("得分/Score", "simsun.ttc", 9) c.yAxis().setLinearScale(0, maxv) # Add a multi-bar layer with 3 data sets and 4 pixels 3D depth #~ layer = c.addBarLayer2(Side, 1) layer = c.addBarLayer() layer.setBarGap(0.2) layer.setBarWidth(150, 48) for index, series in enumerate(series_list): layer.addDataSet(series['value'], color_list[index % len(color_list)], utils.to_utf8(series['name'])) if series_top: legendBox.addKey2(2, utils.to_utf8(series_top['name']), 0xFF6900, 2) markLayer = c.addBoxWhiskerLayer(None, None, None, None, series_top['value'], -1, 0xFF6900) markLayer.setLineWidth(2) markLayer.setDataGap(0.1) markLayer.setDataLabelStyle("simsun.ttc", 9) markLayer.setDataLabelFormat("{value|1}") # Set bar border to transparent. Use soft lighting effect with light direction from # top. layer.setBorderColor(Transparent, softLighting(Top)) #layer.setBorderColor(Transparent, barLighting(0.75, 2.0)) layer.setAggregateLabelFormat("{value|1}") # output the chart return c.makeChart2(PNG)
def create_history_now_future_xychart(title, labels, series_list, series_top, maxv=100): top3, ytd, ave, future_score, point = get_ave_score(series_list) series_list.append(dict(name=u'2012 Top3 Ave', value=top3)) series_list.append(dict(name=u'2012 YTD', value=ytd)) series_list.append(dict(name=u'2011 Ave', value=ave)) # Create a XYChart object of size 540 x 375 pixels c = XYChart(900, 320) # Add a title to the chart using 18 pts Times Bold Italic font #c.addTitle("Average Weekly Network Load", "timesbi.ttf", 18) title = c.addTitle(utils.to_utf8(title), "simsun.ttc", 12) title.setMargin2(20, 0, 10, 30) color_list = BASE_COLOR COLOR_BLUE = 0x0070C0 COLOR_93 = 0x00B050 COLOR_87 = 0xFFD600 COLOR_TOP3_AVE = 0x595443 COLOR_YTD = 0xFF0000 COLOR_AVE = 0x5678A9 # Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical # gradient color from light red (ffdddd) to dark red (880000) as background. Set # border and grid lines to white (ffffff). chart_width = 30 + 190 * len(labels) c.setPlotArea(50, 90, chart_width, 200, c.linearGradientColor(60, 40, 60, 280, 0xffffff, 0xd8e2ec), -1, 0xffffff, 0xffffff) legendBox = c.addLegend(50, 30, 0, "simsun.ttc", 10) legendBox.setBackground(Transparent) #legendBox.setAlignment(TopCenter) legendBox.setHeight(30) # Set the x axis labels c.xAxis().setLabels([utils.to_utf8(label) for label in labels]) # Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5) # Set axis label style to 8pts Arial Bold c.xAxis().setLabelStyle("simsun.ttc", 9) c.yAxis().setLabelStyle("simsun.ttc", 9) # Set axis line width to 2 pixels c.xAxis().setWidth(2) c.yAxis().setWidth(2) c.yAxis2().setWidth(1) # Add axis title c.yAxis().setTitle("得分/Score", "simsun.ttc", 9) c.yAxis().setLinearScale(0, maxv) # Add a multi-bar layer with 3 data sets and 4 pixels 3D depth #~ layer = c.addBarLayer2(Side, 1) layer = c.addBarLayer() layer.setBarGap(0.1) layer.setBarWidth(170, 18) for index, series in enumerate(series_list): values = series['value'] if len(values) > 1: color = COLOR_BLUE else: values.append(future_score) if point == 93: color = COLOR_93 elif point == 87: color = COLOR_87 else: color = COLOR_BLUE name = utils.to_utf8(series['name']) if name == u'2012 Top3 Ave': color = COLOR_TOP3_AVE if name == u'2012 YTD': color = COLOR_YTD if name == u'2011 Ave': color = COLOR_AVE #print values, color, name write_list = [] for value in values: if value == -1 or value > 100: write_list.append(0) else: write_list.append(value) layer.addDataSet(write_list, color, name) for i, v in enumerate(values): if v == -1 or v > 100: if name in (u'2012 Top3 Ave',u'2012 YTD', u'2011 Ave'): layer.addCustomGroupLabel(index, i, " ") else: layer.addCustomGroupLabel(index, i, "N/A") else: layer.setAggregateLabelFormat("{value|1}") layer.setAggregateLabelStyle ('', 10, '0x0000', 0) yMark = c.yAxis().addMark(point, '0x800080', '%s' % point) yMark.setLineWidth(1) yMark.setAlignment(TopCenter) # Set bar border to transparent. Use soft lighting effect with light direction from # top. layer.setBorderColor(Transparent, softLighting(Top)) #layer.setBorderColor(Transparent, barLighting(0.75, 2.0)) #layer.setAggregateLabelFormat("{value|1}") # output the chart return c.makeChart2(PNG)
def create_history_now_future_xychart(title, labels, series_list, series_top, maxv=100): top3, ytd, ave, future_score, point = get_ave_score(series_list) series_list.append(dict(name=u'2012 Top3 Ave', value=top3)) series_list.append(dict(name=u'2012 YTD', value=ytd)) series_list.append(dict(name=u'2011 Ave', value=ave)) # Create a XYChart object of size 540 x 375 pixels c = XYChart(900, 320) # Add a title to the chart using 18 pts Times Bold Italic font #c.addTitle("Average Weekly Network Load", "timesbi.ttf", 18) title = c.addTitle(utils.to_utf8(title), "simsun.ttc", 12) title.setMargin2(20, 0, 10, 30) color_list = BASE_COLOR COLOR_BLUE = 0x0070C0 COLOR_93 = 0x00B050 COLOR_87 = 0xFFD600 COLOR_TOP3_AVE = 0x595443 COLOR_YTD = 0xFF0000 COLOR_AVE = 0x5678A9 # Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical # gradient color from light red (ffdddd) to dark red (880000) as background. Set # border and grid lines to white (ffffff). chart_width = 30 + 190 * len(labels) c.setPlotArea(50, 90, chart_width, 200, c.linearGradientColor(60, 40, 60, 280, 0xffffff, 0xd8e2ec), -1, 0xffffff, 0xffffff) legendBox = c.addLegend(50, 30, 0, "simsun.ttc", 10) legendBox.setBackground(Transparent) #legendBox.setAlignment(TopCenter) legendBox.setHeight(30) # Set the x axis labels c.xAxis().setLabels([utils.to_utf8(label) for label in labels]) # Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5) # Set axis label style to 8pts Arial Bold c.xAxis().setLabelStyle("simsun.ttc", 9) c.yAxis().setLabelStyle("simsun.ttc", 9) # Set axis line width to 2 pixels c.xAxis().setWidth(2) c.yAxis().setWidth(2) c.yAxis2().setWidth(1) # Add axis title c.yAxis().setTitle("得分/Score", "simsun.ttc", 9) c.yAxis().setLinearScale(0, maxv) # Add a multi-bar layer with 3 data sets and 4 pixels 3D depth #~ layer = c.addBarLayer2(Side, 1) layer = c.addBarLayer() layer.setBarGap(0.1) layer.setBarWidth(170, 18) for index, series in enumerate(series_list): values = series['value'] if len(values) > 1: color = COLOR_BLUE else: values.append(future_score) if point == 93: color = COLOR_93 elif point == 87: color = COLOR_87 else: color = COLOR_BLUE name = utils.to_utf8(series['name']) if name == u'2012 Top3 Ave': color = COLOR_TOP3_AVE if name == u'2012 YTD': color = COLOR_YTD if name == u'2011 Ave': color = COLOR_AVE #print values, color, name write_list = [] for value in values: if value == -1 or value > 100: write_list.append(0) else: write_list.append(value) layer.addDataSet(write_list, color, name) for i, v in enumerate(values): if v == -1 or v > 100: if name in (u'2012 Top3 Ave', u'2012 YTD', u'2011 Ave'): layer.addCustomGroupLabel(index, i, " ") else: layer.addCustomGroupLabel(index, i, "N/A") else: layer.setAggregateLabelFormat("{value|1}") layer.setAggregateLabelStyle('', 10, '0x0000', 0) yMark = c.yAxis().addMark(point, '0x800080', '%s' % point) yMark.setLineWidth(1) yMark.setAlignment(TopCenter) # Set bar border to transparent. Use soft lighting effect with light direction from # top. layer.setBorderColor(Transparent, softLighting(Top)) #layer.setBorderColor(Transparent, barLighting(0.75, 2.0)) #layer.setAggregateLabelFormat("{value|1}") # output the chart return c.makeChart2(PNG)