Chart error?

I've created a LineWithDataMarkers chart and added 7 series to the collection. For some reason, it only made the first 4 series correctly. The other 3 are showing up as columns instead of lines with markers. I even tried setting each series' type manually, and that did not change anything.

One thing I found odd is that if I add an 8th series to the chart, it also sets it as a column type, but if I add a 9th and 10th series, it shows 5 of them as lines with markers and the other 5 of them as columns. Is there some setting I missed that is causing this to happen?

Frank

Hi Frank,

Could you please post your code here? I tried the following code and it works fine:

Workbook wb = new Workbook();
wb.Open("d:\\test\\book1.xls");

int chartIndex = wb.Worksheets[0].Charts.Add(ChartType.LineWithDataMarkers, 5, 9, 16, 16);
Chart chart = wb.Worksheets[0].Charts[chartIndex];
chart.NSeries.Add("A1:E1", false);
chart.NSeries.Add("A2:E2", false);
chart.NSeries.Add("A3:E3", false);
chart.NSeries.Add("A4:E4", false);
chart.NSeries.Add("A5:E5", false);
chart.NSeries.Add("A6:E6", false);
chart.NSeries.Add("A7:E7", false);
chart.NSeries.Add("A8:E8", false);

wb.Save("d:\\test\\abc.xls");

My application allows for the possibility of the user requesting a single chart or multiple charts to be created in the same spreadsheet, so I'm not hardcoding the data ranges for the series. I'll try to explain what I'm doing so that it makes sense.

int chartIndex = chartSheet.Charts.Add(ChartType.LineWithDataMarkers, chartStartRow, 0, chartStartRow + 28, 9); //chartStartRow is the starting row for the current chart being created

Aspose.Cells.Chart newChart = chartSheet.Charts[chartIndex];

newChart.SecondValueAxis.IsVisible = true;

newChart.ValueAxis.MajorGridLines.IsVisible = true;

newChart.CategoryAxis.CategoryType = CategoryType.TimeScale;

//Next, I call a function to configure the series that will be in the chart and pass the nseries collection as a parameter

ConfigureSeries(newChart.NSeries, dataRange); //dataRange is the cell range that contains the data for the current chart

//the following code is from my ConfigureSeries function

ConfigureSeries(Aspose.Cells.NSeries chartSeries, Aspose.Cells.Range dataRange)

{

chartSeries.CategoryData = "Data!A" + (dataRange.FirstRow + 1) + ":" + "A" + (dataRange.FirstRow + dataRange.RowCount); //If I'm generating a single chart, this ends up being "A5:A9"

for(int i = 0; i < 7; i++)
{
chartSeries.Add("Data!" + dataRange[0, i].Name + ":" + dataRange[dataRange.RowCount - 1, i].Name, true);
{

}

So if I'm just creating a single chart, the range for the first series ends up being "B5:B9", the second is "C5:C9" all the way through the 7th series which is "H5:H9". This all works correctly. If I look at the data source settings for the chart, all of the data ranges are set correctly.

I also set line marker styles, line colors, marker foreground and background colors, and I mark series 1, 2, 3, and 4 to be plotted on the secondary axis.

chartSeries[1].PlotOnSecondAxis = true; //etc. for series 1, 2, 3, 4

After all of this is done, the data sources for each series is set just as I expected it to be, but for some reason the last 3 series are being set as columns instead of lines with markers.

I’ve also noticed that none of my series are being plotted on the secondary axis as I had set them to. They are all going off of the primary one.

Could you please post a sample file with your expected chart to show your need? Then I can see how to serve your need.

Here is a sample file that I would like to create using Aspose.

- Frank

P.S. I did some testing in a sample application just to see if I could figure out anything that might be causing the problem I'm having. I think I may have found the problem, but I'm not sure why it is happening. Everything works fine until I add a second value axis.

chart.SecondValueAxis.IsVisible = true;

This causes some of the series to be changed to column type instead of line with markers.

Hi Frank,

Thanks for the sample file, we will figure out and response you soon.

Regards

Amjad Sahi

Aspose Nanjing Team

Hi Frank,

Please try this attached fix.

Thanks Laurence. It's almost working right, there is just one other small problem. All of my data series are properly showing up as Line with Markers style, but the same ones that were columns before are automatically plotted on the second axis.

I have 7 total series. Series 0, 5, and 6 should be plotted on the primary axis. Series 1, 2, 3, and 4 should be plotted on the secondary axis. In my code I do this:

chart.NSeries[1].PlotOnSecondAxis = true;

chart.NSeries[2].PlotOnSecondAxis = true;

chart.NSeries[3].PlotOnSecondAxis = true;

chart.NSeries[4].PlotOnSecondAxis = true;

But, when the chart is created, it puts series 4, 5, 6 on the secondary axis. And those are the same series that were previously being set to use the column type before the fix you posted for me.

Frank

Hi Frank,

I find the problem. Please try this fix.

Everything seems to be working correctly now. Thank you for the quick fixes, I really appreciate it.

Frank