Free Support Forum - aspose.com

Change chart default colors

Hello,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I need to change default colors for NSeries(i) in column chart and make it:

#fdac37 <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Orange

#e56f49 Red Dirty

#3882ef Blue

#999966 Yellow Dirty

#ff99cc Pink

#c1f23e Brown Light

#ddd6c6 Grey Org

#66cccc Emerald

#eee176 Yellow

#66cc66 Green

When I try

chart.NSeries(0).Area.ForegroundColor = Color.Orange

I’ve got white color instead of orange for NSeries(0)

What am I doing wrong?

Thanks.

Hi,

Well, Orange color is not present on the standard MS Excel color palette, so you have to update the palette and add the color to it before setting orange color to a column chart series. You may use Workbook.ChangePalette() method for adding all those custom colors which are not present on the palette by default.

If any color is not present in the Standard Color Palette, you have to add it first into the palette before setting it as a fill color of the cell. Since MS Excel color palette (Excel 97 - 2003) has only 56 colors (0-55 indexed) on it, so if a color is not there, you will add the color to the palette replacing any existing color on a specified index position.

For your case, you should add a line of code before setting the color and it will work fine.

e.g..,

Dim workbook As Workbook = New Workbook()

.

.

'Add the orange color to the last index position on the palette.

workbook.ChangePalette(Color.Orange,55)

chart.NSeries(0).Area.ForegroundColor = Color.Orange

Thank you.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks, it works.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I have another question.

Currently default palette is violet, maroon, light yellow, light blue ….

It is the same for different NSeries in Column Stacked chart and for different points in the same NSeries in pie chart.

In my application, I dynamically create different types of charts with different number of NSeries and different number points in the NSeries.

How I can change default palette?

Hi,

Yes it is same for all types of objects.

If you are creating charts in different workbooks (either creating the workbook from the scracth or using an existing source template file), you should update the standard color palettes (in each workbook) with the colors (which are not present on the standard color palette) before setting those colors to a chart nseries or data points or else. Suppose, in a workbook, you want an orange color to a nseries, data point labels and legend background color, you will update the color palette only once (adding orange color to the palette) before setting the color to those objects.

Thank you.

Thanks, I understand it.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

First, I have to update the standard color palettes with desired colors.

oWB.ChangePalette(System.Drawing.Color.Orange, 31)

oWB.ChangePalette(System.Drawing.Color.OrangeRed, 32)

oWB.ChangePalette(System.Drawing.Color.Blue, 33)

oWB.ChangePalette(System.Drawing.Color.YellowGreen, 34)

oWB.ChangePalette(System.Drawing.Color.Pink, 35)

oWB.ChangePalette(System.Drawing.Color.LimeGreen, 36)

oWB.ChangePalette(System.Drawing.Color.Gray, 37)

oWB.ChangePalette(System.Drawing.Color.Indigo, 38)

oWB.ChangePalette(System.Drawing.Color.Yellow, 39)

oWB.ChangePalette(System.Drawing.Color.Green, 40)

My question was how I can change default palette, so I do not have to set new colors for different objects.

For different objects, I have to set colors differently:

ColumnStacked:

chart.NSeries(0).Area.ForegroundColor = Color.Orange

chart.NSeries(1).Area.ForegroundColor = Color.OrangeRed

chart.NSeries(2).Area.ForegroundColor = Color. Blue

……

Every other ColumnStacked chart could have different number of NSeries.

Pie:

chart.NSeries(0).Points(0).Area.ForegroundColor = Color.Orange

chart.NSeries(0).Points(1).Area.ForegroundColor = Color.OrangeRed

chart.NSeries(0).Points(2).Area.ForegroundColor = Color.Blue

chart.NSeries(0).Points(3).Area.ForegroundColor = Color.YellowGreen

chart.NSeries(0).Points(4).Area.ForegroundColor = Color.Pink

chart.NSeries(0).Points(5).Area.ForegroundColor = Color.LimeGreen

chart.NSeries(0).Points(6).Area.ForegroundColor = Color.Gray

……

Every other pie chart could have different number of points.

Currently default palette (violet, maroon, light yellow, light blue ….) is the same for different objects and I don’t have to set it.

How I can change default palette, so I don’t have to set desired colors and application will take colors from new desired default list?

Hi,

Well, the default color palette is related to MS Excel not with Aspose.Cells, check Colors and background patterns. Each Microsoft Excel file has a palette of 56 colors that you can apply to cells, fonts, gridlines, graphic objects, fills and lines in a chart etc. I think the only way you may change the default color palette is using MS Excel i.e…, In MS Excel 2003 …Click Tools|Options|Color tab…click Modify and make custom color to replace existing ones. So you may create some source template files with your desired custom colors set on the palette, use Aspose.Cells to open that excel file and create your chart objects with your desired colors. But if you want to create the excel files from the scratch using Aspose.Cells to create charts with custom colors for different objects, you will update the default palette using Workbook.ChangePalette method to add colors to the palette at different indexed positions.

For further reference about the palette’s colors and their relative indexed positions, kindly check: https://docs.aspose.com/display/cellsnet/Cells+Formatting#CellsFormatting-ColorsandPalette

Thank you.