Datalabel percentage

Hi there

I've the following datatable which I've exported to Excel and created a chart.

Area Sales
1 330
2 485
3 672
4 237
5 94
6 15
7 3
8 20
9 45

When I make the datalabel.isvalueshown = true, along each bar the corresponding sales value is shown. But what I want is to display the corresponding percentage eg 330 / 1901 (17.31%) should be shown against area 1.

I wanted to know whether this is possible with Aspose.cells. I tried datalabel.ispercentageshown = true, but that displayed NOTHING. Could you let me know how could i achieve this?

Regards
Kit

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

Which try of chart are your creating? If you are creating a bar chart or column chart then the percentage will not be shown automatically as MS Excel does not provide this feature for such charts. Percetange values (using IsPercentageShown = true) are shown with chart types like pie charts etc. You may manually calculate the percentage and assign that to the DataLabel.Text property.

Thank You & Best Regards,

Hi Aslam

Thanks for the reply. It was barchart. I will try to set the datalabel's text property. Meanwhile I have come up with another question. I want to set custom colors to the bars. I tried changing Excels palatte colors like

Workbook wb = new Workbook();

wb.ChangePalette(System.Drawing.Color.Green, 55);
wb.ChangePalette(System.Drawing.Color.Red, 54);
wb.ChangePalette(System.Drawing.Color.Yellow, 53);

Createchart();
wb.save("d:\\Chart.xls")

It looks like this has no effect. If the iscolorvaried is set to true, a set of multiple color bars are seen(i mean from the default palette, when set to false a set of blue color bars are seen. Can you help?

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

Well, Workbook.ChangePalette is used to change the default color palette of MS Excel colors and has no affect on Series Colors of the chart. It is used to add the custom colors to the palette to use them. To Change the chart series colors, please use the following code:

chart.NSeries[0].Area.ForegroundColor = Color.Green;

chart.NSeries[1].Area.ForegroundColor = Color.Red;

chart.NSeries[2].Area.ForegroundColor = Color.Yellow;

Thank You & Best Regards,

Hi there

I am trying to create a chart in the Excel (which would be later exported to powerpoint). I took sample code from your site and could successfully create the chart in Excel. I've a seperate data sheet and a separate chart sheet. I am trying to reduce the size of chart in the chartsheet(or rather the size of chart sheet???) and I could not. Here are the cods lines where I tried to change the chartrows and chartCols to 35 and 15 respectively. Is this the right way to reduce the chart size?

Workbook wb = new Workbook();
int chartRows = 55;
int chartCols = 25;
int chartSheetIndex = ChartFromDatatable(wb,chartRows, chartCols,dtData,chartType );
wb.Worksheets.SetOleSize(0,chartRows, 0, chartCols);
wb.Save("d:\\pptx\\FromDt.xls");

// Later.. In this ChartfromDatatable function I have

int chartIdx = chartSheet.Charts.Add(chType, 0,chartRows,0, chartCols);
Chart chart = chartSheet.Charts[chartIdx];

Cheers
Kit

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

Well, I tried changing the size of the Chart manually using MS Excel (Sheet Type = Chart) but it does not allows to change the chart size. I think MS Excel does not support to change the size of the chart in Chart Sheet as well and Aspose.Cells works in same way as MS Excel does. It you know any workaround to achieve this using MS Excel, please share with us and we will look into it.

Thank You & Best Regards,

Hi

Okay, I get the point that chart sheet resizing is not supported in MSexcel. Okay, now could you let me know how to adjust the size of the chart in the chart sheet (this I could do by dragging with the mouse) in Excel.

I also have found an issue with the Datapoint fore color. I wanted to set custom colors to individual datapoints. At the first instance it seemed to work fine. But by taking a closer look, there was difference in the colors. So I checked in debugging mode.

I used some thing like dp.Area.ForegroundColor = custcol[j];

For example my custcol[0] had a color (255,92,161,40) after this stement is executed dp.Area.ForegroundColor had the value (0,92,161,40) Note that alpha value was earlier 255 and now 0. Never mind, I do not use transparent colors. When I opened the excel sheet, I could see the green color but a DIFFERENT shade. So I tried to right click the datapoint and did "Format Datapoint" and found that the color had a different RGB value as Red=128, Green=128 and blue =0. Transparency (alpha) was also 0.

I even tried assigning directly dp.Area.ForegroundColor = Color.FromArgb(255,92,161,40);

It is just the same as explained above. Could you please explain why is the color not exported properly.

Sincerely
Kit

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

KittyKit:

Hi

Okay, I get the point that chart sheet resizing is not supported in MSexcel. Okay, now could you let me know how to adjust the size of the chart in the chart sheet (this I could do by dragging with the mouse) in Excel.

Aspose.Cells also allows to adjust the plot area, please see the following code as sample:

chart.PlotArea.Width = 1500;

chart.PlotArea.Height = 1500;

KittyKit:

I also have found an issue with the Datapoint fore color. I wanted to set custom colors to individual datapoints. At the first instance it seemed to work fine. But by taking a closer look, there was difference in the colors. So I checked in debugging mode.

I used some thing like dp.Area.ForegroundColor = custcol[j];

For example my custcol[0] had a color (255,92,161,40) after this stement is executed dp.Area.ForegroundColor had the value (0,92,161,40) Note that alpha value was earlier 255 and now 0. Never mind, I do not use transparent colors. When I opened the excel sheet, I could see the green color but a DIFFERENT shade. So I tried to right click the datapoint and did "Format Datapoint" and found that the color had a different RGB value as Red=128, Green=128 and blue =0. Transparency (alpha) was also 0.

I even tried assigning directly dp.Area.ForegroundColor = Color.FromArgb(255,92,161,40);

It is just the same as explained above. Could you please explain why is the color not exported properly.

Sincerely
Kit

Well, you need to add your custom color into the color palette before using it. Please see the following documentation links for further details:

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/colors-and-palette.html

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/aspose.cells.workbook.changepalette.html

Thank You & Best Regards,