We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Change chart label

As can bee seen blow that I have a chart i was wondering how i would be able to change the label “per” pro-grammatically though code./

Hi Jim,


I have observed that you need to change the category name “per” instead of labels. Please use following code snippet to change the category axis text.

public static void ModifyChart()
{
//Instantiate PresentationEx class that represents PPTX file
PresentationEx pres = new PresentationEx(“D:\Aspose Data\AsposeChart.pptx”);

//Access first slide
SlideEx sld = pres.Slides[0];

// Add chart with default data
ChartEx chart = (ChartEx)sld.Shapes[0];

//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

//Getting the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;

//Changing Category Name
fact.GetCell(defaultWorksheetIndex, 1, 0, “per”);
fact.GetCell(defaultWorksheetIndex, 2, 0, “gent”);

//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[0];

//Now updating series data
fact.GetCell(defaultWorksheetIndex, 0, 1, “New_Series1”);//modifying series name
for (int i = 0; i < series.Values.Count; i++)
{
if(i==0)
series.Values[i].Value = 90;
else if(i==1)
series.Values[i].Value = 123;
else if(i==2)
series.Values[i].Value = 44;
}
//Take Second chart series
series = chart.ChartData.Series[1];


//Now updating series data
fact.GetCell(defaultWorksheetIndex, 0, 2, “New_Series2”);//modifying series name
for (int i = 0; i < series.Values.Count; i++)
{
if (i == 0)
series.Values[i].Value = 23;
else if (i == 1)
series.Values[i].Value = 67;
else if (i == 2)
series.Values[i].Value = 99;
}

//Now, Adding a new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, “Series 3”), chart.Type);

//Take 3rd chart series
series = chart.ChartData.Series[2];

//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 3, 20));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 3, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 3, 30));
// chart.Type = ChartTypeEx.ClusteredCylinder;

// Save presentation with chart
pres.Write(@“D:\Aspose Data\AsposeChartMoodified.pptx”);


}


Many Thanks,

hi,

i was wondering would it be possible for me to change the values using a for loop with data form an array as when im doing so i make an error

Hi Jim,


Yes you can set the values using arrays. Kindly share the complete sample application used on your end along with issue details. I will try to reproduce the issue and help you out. Please also highlight the code section whereby you are having issue.

Many Thanks,