Create a chart with two Y-axes and one shared X-axis

Hi,

Is it possible to create a chart with two Y-axes and one shared X-axis ?
Just like in this link : http://www.techonthenet.com/excel/charts/2_y_axes.php
If yes, can you please provide an example on how to do it?

Regards,
Moshe

Hi Moshe,


I like to share that Aspose.Slides for .NET allows you to create a chart with multiple types in single chart. Please use the code snippet given below with Aspose.Slides for .NET 6.3.0 for your convenience. Please share, if I may help you further in this regard.

PresentationEx ppt = new PresentationEx();

SlideEx sld = ppt.Slides[0];

// — add chart to slide —

ChartEx ch = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 20, 20, 500, 300);
// ChartEx ch = sld.Shapes.AddChart(ChartTypeEx.Line , 20, 20, 500, 300);

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

// — Delete default generated series and categories —
ch.ChartData.Series.Clear();
ch.ChartData.Categories.Clear();

// — ADD SERIES 1 VALUES —
int[] values = new int[] { 0, 4, 3, 4, 2, 6 };
ch.ChartData.Series.Add(fact.GetCell(0, 0, 1, “Values”), ch.Type);
ChartSeriesEx series1 = ch.ChartData.Series[0];
series1.Format.Line.FillFormat.FillType = FillTypeEx.Solid;
series1.Format.Line.FillFormat.SolidFillColor.Color = Color.Red;
series1.Format.Fill.FillType = FillTypeEx.Solid;
series1.Format.Fill.SolidFillColor.Color = Color.Red;

for (int i = 1; i < 6; i++)
series1.Values.Add(fact.GetCell(0, i, 1, values[i]));

// — ADD TARGET DATA SERIES —

int[] targets = new int[] { 0, 5, 5, 5, 5, 5 };
ch.ChartData.Series.Add(fact.GetCell(0, 0, 3, “Target”), ChartTypeEx.Line);
ChartSeriesEx targetSeries = ch.ChartData.Series[1];
targetSeries.Format.Line.FillFormat.FillType = FillTypeEx.Solid;
targetSeries.Format.Line.FillFormat.SolidFillColor.Color = Color.Green;
targetSeries.Format.Fill.FillType = FillTypeEx.Solid;
targetSeries.Format.Fill.SolidFillColor.Color = Color.Green;

for (int i = 1; i < 6; i++)

targetSeries.Values.Add(fact.GetCell(0, i, 3, targets[i]));

// — ADD LABELS —

for (int i = 1; i < 6; i++)

ch.ChartData.Categories.Add(fact.GetCell(0, i, 0, "point " + i));

//If you want plain line without marker then use following code
/targetSeries.MarkerFill.Fill.FillType = FillTypeEx.NoFill;
targetSeries.MarkerSymbol = MarkerStyleTypeEx.None;
targetSeries.MarkerFill.Line.FillFormat.FillType = FillTypeEx.NoFill;
targetSeries.MarkerSize = 0;
/
targetSeries.MarkerFill.Fill.FillType = FillTypeEx.Solid;
targetSeries.MarkerFill.Fill.SolidFillColor.Color = Color.Blue;

targetSeries.MarkerSymbol = MarkerStyleTypeEx.Diamond;
targetSeries.MarkerFill.Line.FillFormat.FillType = FillTypeEx.Solid;
targetSeries.MarkerFill.Line.FillFormat.SolidFillColor.Color = Color.Green;
targetSeries.MarkerSize = 15;

// — SAVE FILE —
ppt.Save(“D:\Aspose Data\myPPt.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);//, null);


Many Thanks,

Thanks for the quick response.
But I need to have 2 Y-axes: one on the left and one on the right.
Lets say that for “Target” the Y values will be 100,200,300,400,500
(and for “Values” the Y values remain 4,3,4,2,6)
Just like the percent values in this :
http://www.techonthenet.com/excel/charts/images/2_y_axes009.png

Regards,
Moshe

Hi Moshe,


I have tried to access the link shared by you but I don’t have access to the link and cannot open it. Please share your requirements in form of sample presentation so that I may see what you are looking for is actually possible in Aspose.Slides for .NET.

Many Thanks,

Attached please find the chart with 2 Y axes

Regards
Moshe

Hi Moshe,


I have observed the requirement shared by you for the plotting of secondary Y-axis. I have created an issue with ID SLIDESNET-33490 to further investigate that whether it is possible to add the secondary category using Aspose.Slides for .NET or not. I will share the response with you as soon as it will be shared by our development team.

We are sorry for your inconvenience,

Hi Moshe,


The issue shared has been resolved in Aspose.Slides for .NET 6.4.0. Please use the following code snippet to plot the chart series on secondary Y-axis. Please share, if I may help you further in this regard.


PresentationEx ppt = new PresentationEx();

SlideEx sld = ppt.Slides[0];

// — add chart to slide —

ChartEx ch = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 20, 20, 500, 300);
// ChartEx ch = sld.Shapes.AddChart(ChartTypeEx.Line , 20, 20, 500, 300);

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

// — Delete default generated series and categories —
ch.ChartData.Series.Clear();
ch.ChartData.Categories.Clear();

// — ADD SERIES 1 VALUES —
int[] values = new int[] { 0, 4, 3, 4, 2, 6 };
ch.ChartData.Series.Add(fact.GetCell(0, 0, 1, “Values”), ch.Type);
ChartSeriesEx series1 = ch.ChartData.Series[0];
series1.Format.Line.FillFormat.FillType = FillTypeEx.Solid;
series1.Format.Line.FillFormat.SolidFillColor.Color = Color.Red;
series1.Format.Fill.FillType = FillTypeEx.Solid;
series1.Format.Fill.SolidFillColor.Color = Color.Red;

for (int i = 1; i < 6; i++)
series1.Values.Add(fact.GetCell(0, i, 1, values[i]));

// — ADD TARGET DATA SERIES —

int[] targets = new int[] { 0, 5, 5, 5, 5, 5 };
ch.ChartData.Series.Add(fact.GetCell(0, 0, 3, “Target”), ChartTypeEx.Line);
ChartSeriesEx targetSeries = ch.ChartData.Series[1];
targetSeries.Format.Line.FillFormat.FillType = FillTypeEx.Solid;
targetSeries.Format.Line.FillFormat.SolidFillColor.Color = Color.Green;
targetSeries.Format.Fill.FillType = FillTypeEx.Solid;
targetSeries.Format.Fill.SolidFillColor.Color = Color.Green;

for (int i = 1; i < 6; i++)

targetSeries.Values.Add(fact.GetCell(0, i, 3, targets[i]));

// — ADD LABELS —

for (int i = 1; i < 6; i++)

ch.ChartData.Categories.Add(fact.GetCell(0, i, 0, "point " + i));
//If you want plain line without marker then use following code
/targetSeries.MarkerFill.Fill.FillType = FillTypeEx.NoFill;
targetSeries.MarkerSymbol = MarkerStyleTypeEx.None;
targetSeries.MarkerFill.Line.FillFormat.FillType = FillTypeEx.NoFill;
targetSeries.MarkerSize = 0;
/
targetSeries.MarkerFill.Fill.FillType = FillTypeEx.Solid;
targetSeries.MarkerFill.Fill.SolidFillColor.Color = Color.Blue;

targetSeries.MarkerSymbol = MarkerStyleTypeEx.Diamond;
targetSeries.MarkerFill.Line.FillFormat.FillType = FillTypeEx.Solid;
targetSeries.MarkerFill.Line.FillFormat.SolidFillColor.Color = Color.Green;
targetSeries.MarkerSize = 15;

targetSeries.PlotOnSecondAxis = true;

// — SAVE FILE —
ppt.Save(“D:\Aspose Data\myPPt.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);



Many Thanks,

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


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