Defining Graph style

Hi,

I am trying to dinamicaly build a graphic exactly like the one thats in the file that i’ve attached.

I can’t seem to define the background color of the ChartArea, and the text color , althow i have the textfont property and color defined, dosen’t apply to all the text.

I have looked into your exemples in demo pages, but i couldn’t find exactly what i need.

Can you give me an help in this?

Is it possible to programmaticaly define a chart as i need it?

Thanks

Best regard’s

Pedro Glória

Hi Pedro,

Since you are applying custom colors to the series area or so, so you need to add those custom colors to the MS Excel standard color palette first. For your information, Ms Excel standard color palette has only 56 colors. The colors are indexed 0-55. Please check document topic: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/aspose.cells.workbook.changepalette.html
If a color is not present on the palette, we have to add it to the palette, so that we may use use.

Also, please see the document for reference: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/colors-and-palette.html


I have tested with the following sample code using your template excel file, it works fine.

Sample code:

Workbook workbook = new Workbook();
workbook.Open(“f:\test\newex\example.xls”);
//Add the custom color to the palette for the first series.
Color color1;
color1= Color.FromArgb(79, 129, 189);
workbook.ChangePalette(color1, 55);
//Add the custom color to the palette for the second series.
Color color2;
color2= Color.FromArgb(192, 80, 77);
workbook.ChangePalette(color2, 54);
//Add the custom color to the palette for the third series.
Color color3;
color3= Color.FromArgb(155, 187, 89);
workbook.ChangePalette(color3, 53);

Worksheet sheet = workbook.Worksheets[0];

//Create chart
int chartIndex = sheet.Charts.Add(ChartType.ColumnStacked, 5, 1, 29, 10);
Chart chart = sheet.Charts[chartIndex];

//Add the nseries collection to a chart
chart.NSeries.Add(“C28:E30”, false);
//Get or set the range of category axis values
chart.NSeries.CategoryData = “C27:E27”;

for (int i = 0; i < chart.NSeries.Count; i++)
{
chart.NSeries[i].Name = sheet.Cells[27+i, 1].Value.ToString();

}

//Set the custom color for the first data series.
chart.NSeries[0].Area.ForegroundColor = color1;

//Set the custom color for the second data series.
chart.NSeries[1].Area.ForegroundColor = color2;

//Set the custom color for the third data series.
chart.NSeries[2].Area.ForegroundColor = color3;

chart.IsDataTableShown = true;
chart.IsLegendShown = false;
workbook.Save(“f:\test\outputChart1.xls”);


Thank you.