How to change axis values for charts

Hi,
How can i change the values of x-axis, and y-axis in charts.
Suppose, i’ve the data in columns A1 to N10.

I want to take the values of A1 to A10 in x-axis and D1 to D10 in y-axis.
How can i do this situation?

Thanks & Regards
Sankar V

Hi,

See some code snippets for reference:
chart.NSeries.Add(“Data!A1:A10”, true);
chart.NSeries.CategoryData = “Data!D1:D10”;
(the above lines may be inter-changed accordingly)


2)
If you need to change the data series values in x-axis and y-axis in an existing chart in the template Excel file, you may try:
Chart chart = workbook.Worksheets[sheetIndex].Charts[0];
chart.NSeries[0].Values = “=Data!$B$2:$B$40”;
chart.NSeries[0].Name = “=Data!B1”;
chart.NSeries.CategoryData = “=Data!$A$2:$A$40”;


Thank you.

Hi,
I’m getting an error message when tried with both the option.

error message is : “Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index”.

My code is :
(First Option)
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ScatterConnectedByCurvesWithDataMarker, 38, 5, 50, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add(“Data!A1:A10”, true);
chart.NSeries.CategoryData = “Data!D1:D10”;

(Second option)
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ScatterConnectedByCurvesWithDataMarker, 38, 5, 50, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries[0].Values = “=Data!$B$2:$B$40”;
chart.NSeries[0].Name = “=Data!B1”;
chart.NSeries.CategoryData = “=Data!$A$2:$A$40”;

Hi,

Please attach your template file which contains source data for chart here. Also, you may paste your complete sample code for analysis, we will check your issue soon.
I suspect you are not giving valid data range for your data series value axis and category data. For your information, my sample code segments are just examples so you should be careful and should apply data source ranges for the series correctly and accordingly.

Thank you.

Please find the attached excel sheet.

In this sheet for charts, i need to get the data customized.

for Chart1:
for X-axis values i want to take the columns from A14 to A37 and
for y-axis values D14 to D37, in the same i want another for the values on F14 to F37.

for Chart2:
for X-axis values i want to take the columns from A14 to A37 and

for y-axis values N14 to N37

Please suggest me how to do this.

Thanks & Regards
Sankar V

And for the same excel, which i had attached previously, i want to align the data from cells B14 tp U37 to be centered.
I had written like this, to get the borders and centered text, but there is now change.

Aspose.Cells.Range re = cells.CreateRange(“A11”, “U37”);
Aspose.Cells.Style stl = workbook.Styles[workbook.Styles.Add()];
stl.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.TopBorder].Color = Color.Black;
stl.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.LeftBorder].Color = Color.Black;
stl.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.BottomBorder].Color = Color.Black;
stl.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.RightBorder].Color = Color.Black;
stl.VerticalAlignment = TextAlignmentType.Center;
stl.HorizontalAlignment = TextAlignmentType.Center;
StyleFlag flg = new StyleFlag();
flg.Borders = true;
re.ApplyStyle(stl, flg);

Hi,

"And for the same excel, which i had attached previously, i want to align the data from cells B14 tp U37 to be centered. I had written like this, to get the borders and centered text, but there is now change."

You need to make the relevant StyleFlag’s alignment attributes “ON”, see the updated code:

Aspose.Cells.Range re = cells.CreateRange(“A11”, “U37”);
Aspose.Cells.Style stl = workbook.Styles[workbook.Styles.Add()];
stl.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.TopBorder].Color = Color.Black;
stl.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.LeftBorder].Color = Color.Black;
stl.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.BottomBorder].Color = Color.Black;
stl.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.RightBorder].Color = Color.Black;
stl.VerticalAlignment = TextAlignmentType.Center;
stl.HorizontalAlignment = TextAlignmentType.Center;
StyleFlag flg = new StyleFlag();
flg.Borders = true;
flg.VerticalAlignment = true;
flg.HorizontalAlignment = true;

re.ApplyStyle(stl, flg);

Thank you.

For your last post:
“Please find the attached excel sheet.

In this sheet for charts, i need to get the data customized.

for Chart1:
for X-axis values i want to take the columns from A14 to A37 and
for y-axis values D14 to D37, in the same i want another for the values on F14 to F37.

for Chart2:
for X-axis values i want to take the columns from A14 to A37 and

for y-axis values N14 to N37

Please suggest me how to do this”

See your other thread:
http://www.aspose.com/community/forums/269858/changing-the-values-for-charts-axis/showthread.aspx#269858

Thank you.