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

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.

@tedc,
Aspose.Excel is discarded and no more under active development. A new product Aspose.Cells has replaced it that contains all the features of its predecessor along with the support for the latest features in different versions of MS Excel. You can create scatter charts and set all the relevant properties. Following example demonstrates this feature briefly.

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();

// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];

// Adding sample values to cells
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["B1"].PutValue(4);
worksheet.Cells["B2"].PutValue(20);
worksheet.Cells["B3"].PutValue(50);

// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ScatterConnectedByLinesWithDataMarker, 5, 0, 15, 5);

// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);

// Saving the Excel file
workbook.Save("output.xlsx");

Here is the program output:

You can refer to the following article for more information about Charts:
Charts

The latest free trial version can be downloaded here:
Aspose.Cells for .NET(Latest version)

For detailed testing of this new product download a runnable solution here.