这让我疯了。
chart_AllData = slideref.shapes.add_chart(XL_CHART_TYPE.BAR_STACKED_100, x, y, cx, cy, chart_data)
chart = chart_AllData.chart
plot = chart.plots[0]
pointCount = 0
for answer in consolidatedAnswersList: # Looping over the answer codes
print('answer: ', answer)
catBar = plot.series[pointCount].points
for cat in catBar: # Looping over the categories (= the declarations)
fill = cat.format.fill
fill.solid()
colorString = ccpStatistics.gAnswerCodeColorDict.get(answer, 'FFFFFF')
r = int(colorString[0]+colorString[1], 16)
g = int(colorString[2]+colorString[3], 16)
b = int(colorString[4]+colorString[5], 16)
fill.fore_color.rgb = RGBColor(r , g , b)
print('setting ', answer, ' to ', colorString)
pointCount += 1
print(ccpStatistics.gAnswerCodeColorDict)
category_axis = chart.category_axis
category_axis.minor_tick_mark = XL_TICK_MARK.OUTSIDE
category_axis.tick_labels.font.italic = True
category_axis.tick_labels.font.size = Pt(12)
value_axis = chart.value_axis
value_axis.format.line.color.rgb = RGBColor(0 , 0 , 0)
value_axis.tick_labels.font.size = Pt(int(thisPageDict.get('SCALEFONTSIZE', ['18'])[0]))
value_axis.major_tick_mark = XL_TICK_MARK.OUTSIDE
value_axis.has_major_gridlines = True
value_axis.tick_labels.font.color.rgb = RGBColor(0,0,0)
value_axis.major_tick_mark.number_format = '0.0"%"'
chart.has_legend = True
chart.legend.position = XL_LEGEND_POSITION.RIGHT
chart.legend.include_in_layout = False # set to true
chart.legend.font.color.rgb = RGBColor(0,0,0)
chart.legend.font.size = Pt(int(thisPageDict.get('LEGENDSIZE', ['12'])[0]))
plot.has_data_labels = True
data_labels = plot.data_labels
data_labels.position = XL_LABEL_POSITION.CENTER
data_labels.font.size = Pt(int(thisPageDict.get('LEGENDSIZE', ['10'])[0]))
data_labels.font.color.rgb = RGBColor(0x00, 0x00, 0x00)
ccpStatistics.gAnswerCodeColorDict的内容如下:
{'oaq_NoAnswer': 'DCDCDC', 'maq_NoAnswer': 'DCDCDC', 'Answer code': 'Answer code color', '1': 'FF0000', '2': 'FF6600', '3': 'FFC301', '4': '00B050', 'OK': '00B050', 'NOK': 'FF0000', 'NA': '333333', 'NEU': 'FF00FF', 'maq': '3A87AD', 'dq': '660000', 'txta': '660000', 'nq': '660000'}
现在,图表根据系列中的设置正确着色...图例中系列的名称也可以......但图例的颜色与栏中的颜色不对应。
注意,类似的代码似乎在其他方法中运行良好。我现在已经结束了。
答案 0 :(得分:0)
尝试在系列级别而不是在单个点级别设置颜色。
char *p = strchr(s1, '\n');
if (p) *p = 0;
p = strchr(s2, '\n');
if (p) *p = 0;