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

Free Support Forum - aspose.com

Always the same chart

Hi,

the following code generate the same chart’s style but I don’t want any markers on two of them.
codes:
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(“Aspose.Total.lic”);
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet workSheet = workbook.Worksheets.Add(“Source”);
string[] title={“Name”,“number”,“Type”};
workSheet.Cells.ImportArray(title, 0, 0,false);
string[,] values = { { “Bugs Bunny”, “Y”, “Looney Tunes” }, { “Daffy Duck”, “Y”, “Looney Tunes” }, { “Pepe Le Pew”, “N”, “Marvel” }, { “Road Runner”, “Y”, “Looney Tunes” },
{ “Mickey”, “Y”, “Disney” }, { “Donalds”, “N”, “Looney Tunes” }, { “Minie”, “Y”, “Disney” }, { “Dingo”, “N”, “DC Comics” },
{ “Spiderman”, “N”, “Disney” }, { “Thor”, “Y”, “Marvel” }, { “Cyclop”, “Y”, “Marvel” }, { “Phenix”,“N”, “DC Comics” },
{ “Batman”, “Y”, “DC Comics” }, { “Superman”, “N”, “Marvel” }, { “Wonderwoman”, “N”, “Looney Tunes” }, { “Flash”, “Y”, “DC Comics” }};
workSheet.Cells.ImportArray(values, 1, 0);
Aspose.Cells.Pivot.PivotTableCollection pivotTables = workSheet.PivotTables;
int iIndex = pivotTables.Add("=Source!A2:C17", “E3”, “Count”);
Aspose.Cells.Pivot.PivotTable pivot = pivotTables[iIndex];
pivot.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Column, 1);
pivot.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, 2);
pivot.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, 0);
iIndex = workSheet.Charts.Add(Aspose.Cells.Charts.ChartType.Line,
13, 4, 26, 10);
Aspose.Cells.Charts.Chart c = workSheet.Charts[iIndex];
c.PivotSource = “Source!Count”;
iIndex = workSheet.Charts.Add(Aspose.Cells.Charts.ChartType.LineStacked,
27, 4, 40, 10);
c = workSheet.Charts[iIndex];
c.PivotSource = “Source!Count”;
iIndex = workSheet.Charts.Add(Aspose.Cells.Charts.ChartType.LineStackedWithDataMarkers,
41, 4, 54, 10);
c = workSheet.Charts[iIndex];
c.PivotSource = “Source!Count”;

workbook.Worksheets.ActiveSheetIndex = workSheet.Index;
workbook.Save(@“D:\Test\bug.xlsx”);


How Can I generate chart without marker (linked with a pivot table)

Hi,


Well, you need to calculate the charts after adding them, you may call Chart.Calculate() method accordingly, see the added lines of code in bold to your code segment:
e.g
Sample code:

pivot.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Column, 1);
pivot.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, 2);
pivot.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, 0);
iIndex = workSheet.Charts.Add(Aspose.Cells.Charts.ChartType.Line,
13, 4, 26, 10);
Aspose.Cells.Charts.Chart c = workSheet.Charts[iIndex];
c.PivotSource = “Source!Count”;
c.Calculate();

iIndex = workSheet.Charts.Add(Aspose.Cells.Charts.ChartType.LineStacked,
27, 4, 40, 10);
c = workSheet.Charts[iIndex];
c.PivotSource = “Source!Count”;
// c.RefreshPivotData();
c.Calculate();

iIndex = workSheet.Charts.Add(Aspose.Cells.Charts.ChartType.LineStackedWithDataMarkers,
41, 4, 54, 10);
c = workSheet.Charts[iIndex];
c.PivotSource = “Source!Count”;
c.Calculate();

I have tested using your code segment with the added line, it works fine.


Thank you.


Hi,


Hopefully it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.