def multi_percent(): # 数据与标签 data1 = [40, 15, 53, 66, 23, 48, 71, 55, 31, 48, 94, 57] data2 = [50, 35, 64, 22, 17, 67, 84, 53, 20, 78, 94, 61] labels = ['08-05', '08-06', '08-07', '08-08', '08-09', '08-10', '08-11', '08-12', '08-13', '08-14', '08-15', '08-16'] # 数据与标签 # data1 = [40, 15, 53] # data2 = [50, 35, 64] # labels = ['08-05', '08-06', '08-07'] # 图片大小 c = XYChart(600, 400) c.addTitle('解析统计', FONT, 14) # 绘图位置及大小,背景及边框透明,设置网格线颜色 c.setPlotArea(80, 40, 500, 320, Transparent, -1, Transparent, 0xcccccc) # 图例, (left, top, is_vertical?? , font, font_size) c.addLegend(170, 22, 0, FONT, 10).setBackground(Transparent) # 坐标轴颜色,标签字体 # c.xAxis().setColors(Transparent) c.xAxis().setLabelStyle(FONT, 12) c.yAxis().setColors(Transparent) c.yAxis().setLabelStyle(FONT, 12) # 多个数据集 layer = c.addBarLayer2(Side) layer.addDataSet(data1, COLOR, "流量Cache率") layer.addDataSet(data2, COLOR2, "访问数Cache率") # 柱子上显示数据,并设置透明边框,柱子颜色的“光强度”介于 0.8 和 1.3 之间 layer.setAggregateLabelStyle(FONT, 10) layer.setAggregateLabelFormat("{value}%") layer.setBorderColor(Transparent, barLighting(0.8, 1.3)) # X轴标签,最多显示7个标签 c.xAxis().setLabels(labels) c.xAxis().setLabelStep(math.ceil(len(data1) / float(7))) # 顶部空白 c.yAxis().setTopMargin(30) # 最小值,最大值,步进。标签格式 c.yAxis().setLinearScale(0, 100, 20) c.yAxis().setLabelFormat("{value}%") # Output the chart c.makeChart("/temp/chart/multi_percent.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 DoRewardChart_Thread(self, rewardID, size, icon): """This function is generating the reward graph for the incursion journal The image is build opon data from the reward system, which is cached with the policy never, None, None""" reward = self.GetRewardData(rewardID) maxRewardValue = 0 minPlayerCount = 0 maxPlayerCount = 0 allSecurityBandTable = None lowSecurityBandTable = None highSecurityBandTable = None for rewardCriteria, rewardTables in reward.immediateRewards.iteritems( ): if not rewardTables: continue if rewardCriteria == const.rewardCriteriaAllSecurityBands: maxRewardValue = self.GetMaxRewardValue( rewardTables, const.rewardTypeISK) minPlayerCount = self.GetMinRewardPlayerCount(rewardTables) maxPlayerCount = self.GetMaxRewardPlayerCount(rewardTables) allSecurityBandTable = rewardTables[0] break if rewardCriteria == const.rewardCriteriaHighSecurity: highSecurityBandTable = rewardTables[0] elif rewardCriteria == const.rewardCriteriaLowSecurity: lowSecurityBandTable = rewardTables[0] else: continue maxRewardValue = max( maxRewardValue, self.GetMaxRewardValue(rewardTables, const.rewardTypeISK)) minPlayerCount = min(minPlayerCount, self.GetMinRewardPlayerCount(rewardTables)) maxPlayerCount = max(maxPlayerCount, self.GetMaxRewardPlayerCount(rewardTables)) scale = 1.0 / maxRewardValue majorTick = (maxPlayerCount - minPlayerCount) / 4 data = [] labels = [] for x in xrange(minPlayerCount, maxPlayerCount + 1): if allSecurityBandTable is not None: quantity = self.GetQuantityForCount(allSecurityBandTable, x) * scale data.append(quantity) else: quantityHigh = self.GetQuantityForCount( highSecurityBandTable, x) * scale quantityLow = self.GetQuantityForCount(lowSecurityBandTable, x) * scale data.append((quantityHigh, quantityLow)) labels.append(str(x)) chart = XYChart(size, size, BLACK, GRAY, False) chart.setPlotArea(PLOT_OFFSET, PLOT_OFFSET, size - PLOT_OFFSET - PLOT_RIGHT_MARGIN, size - PLOT_OFFSET - PLOT_BOTTOM_MARGIN, DARKGRAY, -1, -1, GRAY, Transparent) if localization.util.GetLanguageID( ) == localization.const.LOCALE_SHORT_ENGLISH: font = 'arial.ttf' titleFont = 'arialbd.ttf' else: font = titleFont = uicore.font.GetFontDefault() chart.addLegend(LEGEND_OFFSET, LEGEND_OFFSET, 0, font, 8).setBackground(Transparent) legend = chart.getLegend() legend.setFontColor(WHITE) chart.addTitle(localization.GetByLabel('UI/Incursion/Reward/Title'), titleFont, 12, WHITE).setBackground(Transparent) yAxis = chart.yAxis() yAxis.setTitle( localization.GetByLabel('UI/Incursion/Reward/PayoutMultiplier'), font, 10, WHITE) yAxis.setColors(GRAY, WHITE) yAxis.setLinearScale(0, 1.02, 0.5, 0.25) xAxis = chart.xAxis() xAxis.setLabels(labels) xAxis.setLabelStep(majorTick) xAxis.setColors(GRAY, WHITE) xAxis.setTitle( localization.GetByLabel('UI/Incursion/Reward/NumberPilots'), font, 9, WHITE) layer = chart.addLineLayer2() layer.setLineWidth(1) if allSecurityBandTable is not None: layer.addDataSet(data, COLOR_HIGH_SEC, localization.GetByLabel('UI/Common/Ratio')) else: dataHigh, dataLow = zip(*data) layer.addDataSet(dataHigh, COLOR_HIGH_SEC, localization.GetByLabel('UI/Common/HighSec')) layer.addDataSet(dataLow, COLOR_NULL_SEC, localization.GetByLabel('UI/Common/LowNullSec')) directory = os.path.normpath( os.path.join(blue.paths.ResolvePath(u'cache:/'), 'Pictures', 'Rewards')) if not os.path.exists(directory): os.makedirs(directory) pictureName = 'rewardchart2_%s_%d_%d.png' % (session.languageID, size, rewardID) resPath = u'cache:/Pictures/Rewards/' + pictureName path = os.path.join(directory, pictureName) imageBuffer = chart.makeChart2(PNG) f = open(path, 'wb') f.write(imageBuffer) f.close() icon.LoadTexture(resPath) icon.SetRect(0, 0, size, size)
def DoRewardChart_Thread(self, rewardID, size, icon): reward = self.GetRewardData(rewardID) maxRewardValue = 0 minPlayerCount = 0 maxPlayerCount = 0 allSecurityBandTable = None lowSecurityBandTable = None highSecurityBandTable = None for rewardCriteria, rewardTables in reward.immediateRewards.iteritems(): if not rewardTables: continue if rewardCriteria == const.rewardCriteriaAllSecurityBands: maxRewardValue = self.GetMaxRewardValue(rewardTables, const.rewardTypeISK) minPlayerCount = self.GetMinRewardPlayerCount(rewardTables) maxPlayerCount = self.GetMaxRewardPlayerCount(rewardTables) allSecurityBandTable = rewardTables[0] break if rewardCriteria == const.rewardCriteriaHighSecurity: highSecurityBandTable = rewardTables[0] elif rewardCriteria == const.rewardCriteriaLowSecurity: lowSecurityBandTable = rewardTables[0] else: continue maxRewardValue = max(maxRewardValue, self.GetMaxRewardValue(rewardTables, const.rewardTypeISK)) minPlayerCount = min(minPlayerCount, self.GetMinRewardPlayerCount(rewardTables)) maxPlayerCount = max(maxPlayerCount, self.GetMaxRewardPlayerCount(rewardTables)) scale = 1.0 / maxRewardValue majorTick = (maxPlayerCount - minPlayerCount) / 4 data = [] labels = [] for x in xrange(minPlayerCount, maxPlayerCount + 1): if allSecurityBandTable is not None: quantity = self.GetQuantityForCount(allSecurityBandTable, x) * scale data.append(quantity) else: quantityHigh = self.GetQuantityForCount(highSecurityBandTable, x) * scale quantityLow = self.GetQuantityForCount(lowSecurityBandTable, x) * scale data.append((quantityHigh, quantityLow)) labels.append(str(x)) chart = XYChart(size, size, BLACK, GRAY, False) chart.setPlotArea(PLOT_OFFSET, PLOT_OFFSET, size - PLOT_OFFSET - PLOT_RIGHT_MARGIN, size - PLOT_OFFSET - PLOT_BOTTOM_MARGIN, DARKGRAY, -1, -1, GRAY, Transparent) if localizationUtil.GetLanguageID() == localization.LOCALE_SHORT_ENGLISH: font = 'arial.ttf' titleFont = 'arialbd.ttf' else: font = titleFont = sm.GetService('font').GetFontDefault() chart.addLegend(LEGEND_OFFSET, LEGEND_OFFSET, 0, font, 8).setBackground(Transparent) legend = chart.getLegend() legend.setFontColor(WHITE) chart.addTitle(localization.GetByLabel('UI/Incursion/Reward/Title'), titleFont, 12, WHITE).setBackground(Transparent) yAxis = chart.yAxis() yAxis.setTitle(localization.GetByLabel('UI/Incursion/Reward/PayoutMultiplier'), font, 10, WHITE) yAxis.setColors(GRAY, WHITE) yAxis.setLinearScale(0, 1.02, 0.5, 0.25) xAxis = chart.xAxis() xAxis.setLabels(labels) xAxis.setLabelStep(majorTick) xAxis.setColors(GRAY, WHITE) xAxis.setTitle(localization.GetByLabel('UI/Incursion/Reward/NumberPilots'), font, 9, WHITE) layer = chart.addLineLayer2() layer.setLineWidth(1) if allSecurityBandTable is not None: layer.addDataSet(data, COLOR_HIGH_SEC, localization.GetByLabel('UI/Common/Ratio')) else: dataHigh, dataLow = zip(*data) layer.addDataSet(dataHigh, COLOR_HIGH_SEC, localization.GetByLabel('UI/Common/HighSec')) layer.addDataSet(dataLow, COLOR_NULL_SEC, localization.GetByLabel('UI/Common/LowNullSec')) directory = os.path.normpath(os.path.join(blue.paths.ResolvePath(u'cache:/'), 'Pictures', 'Rewards')) if not os.path.exists(directory): os.makedirs(directory) pictureName = 'rewardchart2_%s_%d_%d.png' % (session.languageID, size, rewardID) resPath = u'cache:/Pictures/Rewards/' + pictureName path = os.path.join(directory, pictureName) imageBuffer = chart.makeChart2(PNG) f = open(path, 'wb') f.write(imageBuffer) f.close() icon.LoadTexture(resPath) icon.SetRect(0, 0, size, size)
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)