Closed yazh21 closed 7 months ago
Hi, you can use this code right after chart.Plot()
call:
byte[][] colors = new byte[][] {
new byte[] {127,(byte)255, 127},
new byte[] {(byte)200, (byte)200, (byte)200},
new byte[] {(byte)255,(byte)255, 127},
new byte[] {(byte)255, 127, 127},
new byte[] {(byte)255, 0, 0},
new byte[] {0, (byte)255, 0},
new byte[] {0, 0, (byte)255},
new byte[] {80, 80, 80},
new byte[] {90, 80, 80},
new byte[] {100, 80, 80}
};
int pointCount = serie.GetCategoryAxisData().PointCount;
var plotArea = chart.GetCTChart().plotArea;
plotArea.barChart[0].ser[0].dPt = new System.Collections.Generic.List<NPOI.OpenXmlFormats.Dml.Chart.CT_DPt>();
for (int i = 0; i < pointCount; i++)
{
plotArea.barChart[0].ser[0].dPt.Add(new NPOI.OpenXmlFormats.Dml.Chart.CT_DPt());
plotArea.barChart[0].ser[0].dPt[i].idx = new NPOI.OpenXmlFormats.Dml.Chart.CT_UnsignedInt() { val = (uint)i};
plotArea.barChart[0].ser[0].dPt[i].spPr = new NPOI.OpenXmlFormats.Dml.Chart.CT_ShapeProperties();
plotArea.barChart[0].ser[0].dPt[i].spPr.AddNewSolidFill().AddNewSrgbClr().val = colors[i];
}
You can also use theme colors:
chart.GetCTChart().plotArea.barChart[0].varyColors = new NPOI.OpenXmlFormats.Dml.Chart.CT_Boolean() { val = 1 };
I have code to Generate Excel File where with my data on excel sheet , it creates Column Chart using Npoi package. In that I have 4 columns in my column chart where all columns color is blue by default. I want to set custom colors for each Column in Column chart that is 4 different colors for 4 columns in column chart.How to Achieve this? This is sample of Chart Generated
This is sample of Chart Wanted
https://github.com/artem-iron/AreaAndPieChartsExample
Originally posted by @artem-iron in https://github.com/nissl-lab/npoi/issues/866#issuecomment-1183971051