Change Category Axis label range of a ChartEx

Hi,


I’m trying to get access to the range of the labels from the CategoryAxis.
In PPT 2010 it’s done by selecting the chart, then in Design tab -> Select Data, from the popup window I select Edit under Horizontal (Category) Axis Labels, this allows me to select the appropriate cells from within the worksheet which will be filling the Category Axis bar in my chart.

Any idea if / how that can be done in Aspose?

Thank you,
Pierre

Hi Pierre,


I have tried to understand the information shared by you but have not been able to completely understand that. Can you please share some more details along with snapshot of the requirements. Please also share the sample presentation as well and I will help you further in this regard.

Many Thanks,

Hi Mudassir,

I am trying to draw a ChartEx and edit it’s Category Axis labels.

To do that in PPT, you have to insert a Chart, Select the Chart -> Design Tab (in Chart Tools section) -> Select Data (this opens the embedded excel worksheet of the chart) -> from the Popup Window that appears -> Click Edit from the left column right under Horizontal (Category) Axis Labels text.

This allows you to select the cell range inside the embedded worksheet from which the category axis will be reading its label values.

Here’s a link for a screenshot that elaborates how this can be done following the above steps:
https://dl.dropbox.com/u/4244333/Functionality.png

I want to do that programmatically in Aspose using C#, but am not able to find any reference to the actual Axis Data Range (excel cells) of the Category Axis.

I hope this sounds a bit clearer.

Thank you!
Pierre

Hi Pierre,


I have observed the requirements shared by you. You seem interested in editing the categories labels. I have prepared the sample code for you and have two methods to achieve that. Use any which will suit you. Please also visit this documentation link for your kind reference as well. In the shared link, I have shared adding new categories and series inside chart.

public static void ChangeChartCategory()
{
String path=@"D:\Aspose Data";
PresentationEx pres = new PresentationEx(path + “SampleChart2.pptx”);

SlideEx slide = pres.Slides[0];
ChartEx chart = (ChartEx)slide.Shapes[0];

ChartDataEx chData = chart.ChartData;

//First Way
/* chData.Categories[0].ChartDataCell.Value = “Cat 1”;*/
chData.Categories[1].ChartDataCell.Value = “Cat 2”;
chData.Categories[2].ChartDataCell.Value = “Cat 3”;
chData.Categories[3].ChartDataCell.Value = “Cat 4”;
//Second Way
//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
//Getting the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;

int Cat1Row = chart.ChartData.Categories[0].ChartDataCell.Row;
int Cat1Col = chart.ChartData.Categories[0].ChartDataCell.Column;
//Changing chart Category Name
fact.GetCell(defaultWorksheetIndex, Cat1Row, Cat1Col, “Modified Category 1”);

pres.Write(@“D:\Aspose Data\SampleChart_Modified.pptx”);
}


Many Thanks,

Hi Mudassir,


Thank you for your reply.

Is it possible to assign multiple cells for each category label?
As in PPT, it is possible to do it by selecting 2 columns for the Axis Label Range instead of a single column.

Thanks!
Pierre

Hi Pierre,


I regret to share the that this option is not available in Aspose.Slides. I feel that the same option is even unavailable in PowerPoint as well. For your convenience, I have shared the image highlighting the merge feature being disabled for chart data. Please share, if I may help you further in this regard.

Many Thanks,

Hi Mudassir,

Thank you answering about another concern I had in mind. Actually I wanted to merge 2 cells together, and I am able to do that myself manually using PPT. You can check this link for a screenshot:
https://dl.dropbox.com/u/4244333/Merge.PNG
I’m not sure why it is doable from my side and not from your side, probably because I am personally plotting the chart programmatically.

My previous question was concerning a selection of 2 columns for the Data Range of the Category Axis Labels, you can check another screenshot (https://dl.dropbox.com/u/4244333/Select2Columns.PNG) for this attempt, this is easily done in PPT by following the steps I mentioned above and selecting a range of 2 columns for the Category Axis Labels instead of a single column.

Let me know if anything is unclear.

Thank you!
Pierre

Hi Pierre,


I have worked over your requirements for merging two cells of category labels. I like to share that there is no direct way available in Aspose.Slides for .NET to merge the excel sheet cells and nor it lies in Aspose.Slides domain. However, Aspose.Slides allows to export the chart data in workbook memory stream. This can be accessed using Aspose.Cells and make the necessary changes for merging the respective cells and saving the workbook back to memory stream. Then loading the saved memory stream in chart data to see the reflected changes. Please use the following sample code to serve the purpose. But it will also involve Aspose.Cells in it.

public static void ChangeChartCategory()
{
String path=@“D:\Aspose Data”;
PresentationEx pres = new PresentationEx(path + “SampleChart2.pptx”);

SlideEx slide = pres.Slides[0];
ChartEx chart = (ChartEx)slide.Shapes[0];

ChartDataEx chData = chart.ChartData;

//First Way
/* chData.Categories[0].ChartDataCell.Value = “Cat 1”;*/
chData.Categories[1].ChartDataCell.Value = “Cat 2”;
chData.Categories[2].ChartDataCell.Value = “Cat 3”;
chData.Categories[3].ChartDataCell.Value = “Cat 4”;
//Second Way
//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
//Getting the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;

int Cat1Row = chart.ChartData.Categories[0].ChartDataCell.Row;
int Cat1Col = chart.ChartData.Categories[0].ChartDataCell.Column;
//Changing chart Category Name
fact.GetCell(defaultWorksheetIndex, Cat1Row, Cat1Col, “Modified Category 1”);

//Logic for merging category labels

MemoryStream mem = chart.ChartData.ReadWorkbookStream();
mem.Position = 0;
Workbook wb = new Workbook(mem);
Worksheet work = wb.Worksheets[0];
work.Cells.Merge(Cat1Row, Cat1Col, 2, 1);
MemoryStream ms2 = new MemoryStream();
wb.Save(ms2, SaveFormat.Auto);
ms2.Position = 0;

chart.ChartData.WriteWorkbookStream(ms2);


pres.Write(@“D:\Aspose Data\SampleChart_Modified.pptx”);
}

For your this question, “My previous question was concerning a selection of 2 columns for the Data Range of the Category Axis Labels”, can you please what actually you wish to achieve by selection of categories columns. I like to share that using Aspose.Slides, you can programatically access each category or series.

Many Thanks,

Hi Mudassir,


Thank you for your reply.

Concerning the merging, what you suggested might be an interesting workaround.

Regarding my concern, you can check the chart that I want to plot in the attached presentation. I have created that manually in PPT 2010.
As you can notice, the CategoryAxis is formed by 2 columns inside the embedded worksheet.

Thank you!
Pierre

Hi Pierre,


I have observed the requirement shared. You are actually looking for multi level category axis labels. I regret to share that currently the support is not available in Aspose.Slides. I have created an issue with ID SLIDESNET-33982 as new feature request to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

We are sorry for your inconvenience,

The issues you have found earlier (filed as SLIDESNET-33982) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(5)