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

Free Support Forum - aspose.com

How to get the each cell 's data and postion in chart

how to get the data and postion(row num and column num ) of each cell in chart,particularly when the data workbook is Irregular(as photo shown)

Hi,

I have observed your requirements of getting row and column index of chart data. Actually, you can get the value and workbook index for every chart data point inside chart series. The charts are organized in the form of series and every series has got chart data points. Please try using the following sample code on your end to serve the purpose.

public static void TestGetChartCell()
{
Presentation pres = new Presentation();

ISlide slide = pres.getSlides().get_Item(0);

// Creating the default chart
IChart chart = slide.getShapes().addChart(ChartType.ClusteredBar, 0, 0, 400, 400);

// Getting the default chart data worksheet index
int defaultWorksheetIndex = 0;

// Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

IChartSeries series = chart.getChartData().getSeries().get_Item(0);

int iCol = series.getDataPoints().get_Item(1).getValue().getAsCell().getColumn();
int iRow = series.getDataPoints().get_Item(1).getValue().getAsCell().getRow();
pres.save(“C:\Aspose Data\AsposeChart_out.pptx”, SaveFormat.Pptx);
}

Many Thanks,

The major porblem is how to get and set the names of series and categories.
I found I can use these code to get and set the value of categorise:

IChartCategoryCollection categoryCol = chart.getChartData().getCategories();
int ySize = categoryCol.size();
for(int y=0;y <ySize; y++){
String yValue = categoryCol.get_Item(y).getValue().toString();
categoryCol.get_Item(y).setValue(yVlaue + “_test”);
}
but I only found how to get the name of series,but I don’t know how to set the name of series.

Hi,


I have observed your requirements. I have shared a piece of code in a text file with you. This will help you to achieve your requirements. Please share feedback with us if there is still an issue.

Best Regards,

Hi,

I have further observed your requirements and suggest you to please try using following sample code to modify the category as well as series name for the chart. I hope the shared information will be helpful.

public static void TestGetChartCell()
{
Presentation pres = new Presentation();

ISlide slide = pres.getSlides().get_Item(0);

// Creating the default chart
IChart chart = slide.getShapes().addChart(ChartType.ClusteredBar, 0, 0, 400, 400);

// Getting the default chart data worksheet index
int defaultWorksheetIndex = 0;

// Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

IChartSeries series = chart.getChartData().getSeries().get_Item(0);
IChartCategory cat= chart.getChartData().getCategories().get_Item(0);

int catRow=cat.getAsCell().getRow();
int catCol=cat.getAsCell().getColumn();

int iColFirstDataPoint = series.getDataPoints().get_Item(0).getValue().getAsCell().getColumn();
int iRowFirstDataPoint = series.getDataPoints().get_Item(0).getValue().getAsCell().getRow();

int SeriesRow =series.getName().getAsCells().get_Item(0).getRow();
int SeriesCol =series.getName().getAsCells().get_Item(0).getColumn();

fact.getCell(0,SeriesRow, SeriesCol).setValue(“Series Modified”);
String ModifiedSeriesName=series.getName().toString();

fact.getCell(0,catRow, catCol).setValue(“Cat Modified”);
String ModifiedCatName=cat.getValue().toString();

pres.save(“C:\Aspose Data\AsposeChart_out.pptx”, SaveFormat.Pptx);
}

Many Thanks,