Free Support Forum - aspose.com

How to set x-axis and y-axis values for each point in Scatter chart in .NET

If you’re trying to set ASeries.Values prop like this:

chart.NSeries[0].Values = “B5:C5”;

Aspose create two point, where x-value for each point is 1,2,3… and so on.
I want to set X-value to other values - but there’s no properties at neither Aspose’s ASeries obj nor Aspose’s Point obj.

Can you advise, how can i create real scatter-chart?

Thanks very much!

X-value setting is not supported yet. I will add this feature to Aspose.Excel in next release. It will available within one week.

Please download v2.8.1. Now you can use ASeries.XValues property to set it.

Thanks a lot.
Now i’m trying to check how it works…

Is there a trick to setting the X values for a ScatterConnectedByLinesWithDataMarker chart? I tried the XValues property but it is ignored completely.
I do not have a license yet but I have the latest version 3.x and we are on the brink of buying 4 licences if we can get the scatter chart to work.

my code is as follows where ‘seriesCol’ is the NSeries collection of the chart:

seriesCol.Add(“A7:A12”, true);
oSeries = seriesCol[seriesCol.Count - 1];
oSeries.Values = “=Data!I7:I12”;
oSeries.XValues = “=Data!G7:G12”;

In other words, the x axis data is in column G rows 7:12 and the Y axis values are in column I, same rows. When I Add the series, I use any similar sized column it doesn’t seem to matter, even if I use either the same data as my Y or my X values.
I always get integers starting at 1.

In previous version, XValues is only supported for Scatter chart. I enhanced it in the attached fix. Now all scatter types chart are supported.

Following is the sample code:

Excel excel = new Excel();
excel.Worksheets.Add();

excel.Worksheets[1].Name = "Data";

excel.Worksheets[1].Cells["A1"].PutValue(1);
excel.Worksheets[1].Cells["A2"].PutValue(2);
excel.Worksheets[1].Cells["A3"].PutValue(3);

excel.Worksheets[1].Cells["b1"].PutValue(4);
excel.Worksheets[1].Cells["b2"].PutValue(5);
excel.Worksheets[1].Cells["b3"].PutValue(6);

Charts charts = excel.Worksheets[0].Charts;
Chart chart = charts[charts.Add(ChartType.ScatterConnectedByLinesWithDataMarker, 10, 10, 20, 15)];
//Chart chart = charts[charts.Add(ChartType.Scatter, 10, 10, 20, 15)];

chart.NSeries.Add("Data!A1:A3", true);
chart.NSeries[0].XValues = "Data!B1:B3";

Thank you for the prompt response.
If I do not add the chart to the excel object, I can view the xls file in my browser.
If I include the chart, it now returns an Exception “Invalid Worksheet name”.

excel.Save(“book2.xls”, SaveType.OpenInBrowser, FileFormatType.Default, this.Response);

I got it working now for a very simple data set so there must be something wrong with my data. I will work on it some more so you can ignore my last message.