Free Support Forum - aspose.com

Updating chart data

Hi Team,

I am trying to modify an existing chart on the ppt.
I am able to update, add , remove the categories and series as well as modify the data points, but if i open the excel containing the data for chart it contains the original data.

Is there a way of modifying the excel data?

Thanks.

@siddhanntarora,

I have observed your comments. Can you please share source files sample project so that we may further investigate to help you out. Also please share complete details of environment.

var categories = chart.ChartData.Categories;
var categoriesCount = categories.Count;
categories[0].Value = “Updated Row 1”;
categories[1].Value = “Updated Row 2”;
//categories[2].Value = “Updated Row 3”;
for (int i = categoriesCount - 1; i >= 2 ; i–)
{
categories.RemoveAt(i);
}

        var series = chart.ChartData.Series;

        var seriesCell = (ChartCellCollection)(series[0].Name.Data);
        seriesCell[0].Value = "Column 1";
        series[0].DataPoints[0].Value.Data = 3434344445;
        series[0].DataPoints[1].Value.Data = 78099788737;
        var seriesCount = series[0].DataPoints.Count;
        for (int i = seriesCount - 1; i >= 2; i--)
        {
            series[0].DataPoints.RemoveAt(i);
        }


        int defaultWorksheetIndex = 0;
        
        IChartDataWorkbook data = chart.ChartData.ChartDataWorkbook;

how do u update chartdataworkbook?

@siddhanntarora,

When you remove the chart data points values in chart, they get de-linked from excel sheet cells. In order to clear the excel sheet for chart data, you can try using following sample code.

    chart.ChartData.ChartDataWorkbook.Clear();

@mudassir.fayyaz,

Is there a way of partially clearing the chartdataworkbook?
As per my requirement the existing chart would have some predefined data let say around 11 rows, now when i clone the slide i might just want 5 rows.

So i am setting the categories and series as per the requirement, it works fine but when i do “Edit Data” on chart the excel sheet still contains 11 rows.

i can use
chart.ChartData.ChartDataWorkbook.Clear(), but i lose the formatting and will have to first store the formatting and then reapply it.

Hence i just want to clear a part of the ChartDataWorkbook, let say only the 6 rows, is there a way of achieving this?

I hope i am able to clarify myself.

@siddhanntarora,

In that case, you can select the actual chart workbook cell for respective chart category or series data point and then set that empty before deleting that from chart. You may use something like following in your implementation.

     int defWorksheetIndex = 0;
    var categories = ch.ChartData.Categories;
    var categoriesCount = categories.Count;
    categories[0].Value = "Updated Row 1";
    categories[1].Value = "Updated Row 2";
    //categories[2].Value = “Updated Row 3”;
    int CellRow =0, CellColumn = 0;
    for (int iCnt = categoriesCount-1; iCnt >= 2 ; iCnt--)
    {
        var cat = categories[iCnt];
        var chartDataCell = cat.AsCell;
        CellRow = chartDataCell.Row;
        CellRow = chartDataCell.Column;
        chartDataCell.Value = String.Empty;
        categories.RemoveAt(iCnt);
    }

    var chartseries = ch.ChartData.Series;

    var seriesCell = (ChartCellCollection)(chartseries[0].Name.Data);
    seriesCell[0].Value = "Column 1";
    chartseries[0].DataPoints[0].Value.Data = 3434344445;
    chartseries[0].DataPoints[1].Value.Data = 78099788737;
    var seriesCount = chartseries[0].DataPoints.Count;
    for (int i = seriesCount - 1; i >= 2; i--)
    {
        var datapoint = chartseries[0].DataPoints[i];
        var chartDataCell = datapoint.Value.AsCell;
        CellRow = chartDataCell.Row;
        CellRow = chartDataCell.Column;
        chartDataCell.Value = String.Empty;
        chartseries[0].DataPoints.RemoveAt(i);
    }

@mudassir.fayyaz Is there a way to resize the range of the excel workbook.

I can do the same when i do Edit Data on a ppt, can we achieve this using aspose?

@siddhanntarora,

The above sample code that I have shared is infact a mechanism using Aspose.Slides for Java to clear chart data points for series and chart categories from chart workbook.

Hello,

I also have same requirement to update the chart data dynamically.
Is there way to delete existing workbook and add new workbook as we have ability to do the same in apache poi.

OR

Is there way to replace series data directly with new categories and new data point value

@madhukardevale,
Welcome to our community! Please describe your issue and more details for your requirements in a new topic.

I am setting min, max, major, minor value for chart but it is not reflecting on chart

@madhukardevale,

At the moment, there are no such possibilities in Aspose.Slides. Could you please describe why you need these features?

Please share a code example and screenshots with expected and actual results.