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

Free Support Forum - aspose.com

ChartDataCellFactory problem

I am trying to create a slide presentati​on with a chart on the slide, I am looking at the example 'creating a chart from scratch' and am having problems with being able to use the ChartDataC​ellFactory​ functional​ity to change and add data to the worksheet (it does not exist)? The chart is a ChartEx.

The Code I am looking at:

//Instantiate PresentationEx class that represents PPTX file

PresentationEx pres = new PresentationEx();

//Access first slide

SlideEx sld = pres.Slides[0];

// Add chart with default data

ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 0, 0, 300, 300);

//Setting the index of chart data sheet

int defaultWorksheetIndex = 0;

//Getting the chart data worksheet

ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;

//Delete default generated series and categories

chart.ChartData.Series.Clear();

chart.ChartData.Categories.Clear();

int s = chart.ChartData.Series.Count;

s = chart.ChartData.Categories.Count;

//Adding new series

chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);

chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);

//Adding new categories

chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));

chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));

chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));

//Take first chart series

ChartSeriesEx series = chart.ChartData.Series[0];

//Now populating series data

series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));

series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));

series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));

//Take second chart series

series = chart.ChartData.Series[1];

//Now populating series data

series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));

series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));

series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));

// Save presentation with chart

pres.Write(@"D:\AsposeChart.pptx");

Hi Steven,


Thanks for your interest in Aspose.Slides.

Can you please share which version of Aspose.Slides for .NET you are using.

Thanks and Regards,

I downloaded the latest TESTING DLL's yesterday:

Cells: 7.0.1
Slides: 5.5.0

Hi Steven,


I have investigated the issue shared by you and tried to export chart data to stream and read that in Workbook. As a result of this the excel file generated is empty and has no data. Moreover, when I double click chart in presentation to edit data, it too is empty. Is this the issue you have been facing. I have created an issue with ID 30830 in our issue tracking system to further investigate and resolve the issue.

//Instantiate PresentationEx class that represents PPTX file
PresentationEx pres = new PresentationEx();

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

// Add chart with default data
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 0, 0, 300, 300);

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

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

//Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;

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

//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, “Caetegoty 1”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, “Caetegoty 2”));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, “Caetegoty 3”));

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

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

//Take second chart series
series = chart.ChartData.Series[1];

//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));
MemoryStream ms = new MemoryStream();
chart.ChartData.WriteWorkbookStream(ms);
ms.Position = 0;
Workbook wb=new Workbook(ms);

wb.Save(“D:\AsposeData.xls”);
// Save presentation with chart
pres.Write(@“D:\AsposeChart.pptx”);

We are sorry for your inconvenience,

No, the problem I am having is I am getting an error at the 'ChartDataCellFactory' line - it does not exist. I have everything working, I can change the cell values and I get a chart, but I am unable to add anything new to the workbook.

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

Hi Steven,


Please share the complete working project code with us so that I may try reproducing the issue on my end as I have not been able to encounter any error while accessing ChartDataCellFactory.

Thanks and Regards,

I have included the code I am trying to use below. You will see ‘ChartDataCellFactory’ is not colored and the resulting error below. What am I missing?

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Text;
using System.IO;
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Pptx;
using Aspose.Slides.Pptx.Charts;
using Aspose.Slides.Effects;
using Aspose.Slides.Export;
using Aspose.Slides.Odp;
using Aspose.Slides.Util;
using Aspose.Cells;
using Aspose.Cells.Charts;
using Aspose.Cells.DigitalSignatures;
using Aspose.Cells.GridFormula;
using Aspose.Cells.GridWeb;
using Aspose.Cells.Markup;
using Aspose.Cells.Pivot;
using Aspose.Cells.Properties;
using Aspose.Cells.Rendering;
using Aspose.Cells.Tables;

public partial class admin_testing_aspose_test4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PresentationEx pres = new PresentationEx();
SlideEx sld = pres.Slides[0];
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 0, 0, 300, 300);
int defaultWorksheetIndex = 0;
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
}
}

HERE IS THE ERROR:

Error Caught in Page_Error event (Global.asax)


Error in: http://localhost:1154/wwww/wwww/testing/aspose_test4.aspx

Error Message: c:\Inetpub\wwwroot\wwww\wwww\testing\aspose_test4.aspx.cs(51): error CS0246: The type or namespace name ‘ChartDataCellFactory’ could not be found (are you missing a using directive or an assembly reference?)

I have attached a .xls file I created from one of your examples. Is there a way I can add the chart on the spreadsheet to a pptx slide? I am looking for a way to convert DataSet information into slides.

Thanks,

Steven Speer
216.224.3825

Hi Steven Speer,

I am extremely sorry for delayed response. I have used the code snippet shared by you and have not encountered issue using Aspose.Slides for .NET 5.5.0 while accessing ChartDataCellFactory. For your kind reference, I have also attached the project code that raise no issue.

Secondly, the only way to add the workbook chart in presentation is to add using Ole frame. Please visit this link for code snippet to add the chart as Ole frame. If you are interested in replacing the chart data in the presentation with that in your workbook and assuming that it should replace the chart, then it is unfortunately not possible. You need to associate every cell containing data to particular series and categories to get things going on. Hope it answers the query.

Thanks and Regards,

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


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi Steven,


We have observed and resolved the issue. The modified code snippet is attached for your kind reference. The issue was when getting the excel file from stream. The following correction was made in code.

MemoryStream ms = new MemoryStream();
ms = chart.ChartData.ReadWorkbookStream();

Many Thanks,