Free Support Forum - aspose.com

Use of charts won't work as usual after new version was released

Hi all,

I'm using aspose.cells to build files containing charts which are linked to a powerpoint file. After installing release 4.4.0.24 I had to change following lines of code from

excel.Worksheets[0].DesignCharts[0].NSeries.CategoryData = labels;
excel.Worksheets[0].DesignCharts[0].NSeries.Add(range, true);


to

excel.Worksheets[0].Charts[0].NSeries.CategoryData = labels;
excel.Worksheets[0].Charts[0].NSeries.Add(range, true);

and the charts color changed and the labels of each bar in chart have been gone, combined charts (bar and line) are not generated correctly (lines are missing).

Last known working version is 4.1.2.6.

bets regards

Jörg

Hi,

Yes, in the newer Aspose.Cells versions (4.4.1 - 4.5.0 (latest)), DesignerCharts API obsoleted. Instead you will use Charts for both designer and new charts.

Kindly try the latest version (4.5.0) downloading from the site, hopefully it works fine for the issue you have mentioned.

If you still find the issue, kindly do post your template file(s) with sample code to reproduce the issue. We will check it soon.

Thank you.

Hi Amjad,

new version did not work :(. Please find attached my sample. Folder Should Look like this shows sample output with old version. You can easily switch between the two versions an regenerate the charts by referencing old version out of folder binaries\old or referencing new version out of folder binaries\new.

best regards

Jörg

Hi,

Thanks for providing the template project.

We will figure out your issue soon.

Thank you.

Hi,

Well, we have checked your project. I think you want to set the existing series data but in your code you are adding new series. If you want to set existing series data of your designer chart, you should not call .Add method. You may try to change your code as follows especially for tha bar chart which has already a single series in the templat chart:

excel.Worksheets[0].Charts[0].NSeries[0].Values = range;
excel.Worksheets[0].Charts[0].NSeries.CategoryData = labels;

For the combined chart, since you have two data series in your designer chart, so, you may set the series accordingly.

For further reference, please check the following docs:

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/manipulating-designer-charts.html

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/creating-custom-charts.html

Thank you.

Hi,

thank you so far, the data is shown correctly in chart after I changed the logic. But the color isn't correct in combined chart (pl see attached image).

what I changed for bar chart:

excel.Worksheets[0].Charts[0].NSeries[0].Values = range;

excel.Worksheets[0].Charts[0].NSeries.CategoryData = labels;

and what I changed for combined chart:

if(row != 1)

{

// set range start and end

string labelStart = Aspose.Cells.CellsHelper.CellIndexToName(1, 0);

string labelEnd = Aspose.Cells.CellsHelper.CellIndexToName(row - 1, 0);

string rangeStart = Aspose.Cells.CellsHelper.CellIndexToName(1, 1);

string rangeEnd = Aspose.Cells.CellsHelper.CellIndexToName(row - 1, 1);

string rangeStart2 = Aspose.Cells.CellsHelper.CellIndexToName(1, 2);

string rangeEnd2 = Aspose.Cells.CellsHelper.CellIndexToName(row - 1, 2);

string range = String.Format("{0}!{1}:{2}", wks.Name, rangeStart, rangeEnd);

string range2 = String.Format("{0}!{1}:{2}", wks.Name, rangeStart2, rangeEnd2);

string labels = String.Format("{0}!{1}:{2}", wks.Name, labelStart, labelEnd);

//* Aspose 4.4.0.24

// excel.Worksheets[0].Charts[0].NSeries.Add(range, true);

// excel.Worksheets[0].Charts[0].NSeries.CategoryData = labels;

excel.Worksheets[0].Charts[0].NSeries.CategoryData = labels;

excel.Worksheets[0].Charts[0].NSeries[1].Values = range2;

excel.Worksheets[0].Charts[0].NSeries[0].Values = range;

// excel.Worksheets[0].DesignCharts[0].NSeries.Add(range, true);

// excel.Worksheets[0].DesignCharts[0].NSeries.CategoryData = labels;

}

What could cause this behavior?

thanks in advance

Jörg

Hi,

Well you did not format the bar series in the template designer charts, so it will come with default color(blue). I think you may try to format series at runtime with ease. I add a few lines to format the two series and they work fine, kindly consult it:

...........

excel.Worksheets[0].Charts[0].NSeries.CategoryData = labels;

excel.Worksheets[0].Charts[0].NSeries[1].Values = range2;

excel.Worksheets[0].Charts[0].NSeries[0].Values = range;

excel.Worksheets[0].Charts[0].NSeries[0].Area.ForegroundColor = System.Drawing.Color.Red;

excel.Worksheets[0].Charts[0].NSeries[1].Line.Color = System.Drawing.Color.Yellow;

excel.Worksheets[0].Charts[0].NSeries[1].MarkerForegroundColor = System.Drawing.Color.Red;

excel.Worksheets[0].Charts[0].NSeries[1].MarkerBackgroundColor = System.Drawing.Color.Green;

// excel.Worksheets[0].DesignCharts[0].NSeries.Add(range, true);

// excel.Worksheets[0].DesignCharts[0].NSeries.CategoryData = labels;

}

Thank you.

ok,

pitty thing is that I didn't change anything, except replaceing DesignerCharts against Charts and now I do need to change a lot (up to 20 charts). And charts are already there and they're configured, why setting color or anything else again via code?

regards

Jörg

solution is set charts series data label format to automatic and it works

regards

Jörg

... and update each Value range separately and not at once like it was with DesignerCharts

regards

Jörg

Hi,

Please try this fix.

We have fixed the bug of the auto color of series.