Posted by a ceTe Software moderator
Hello,
Yes, you can add two Y-axes to a single chart using DynamicPDF Generator for .NET. You will need to create two NumericYAxis and assign them to the required LineSeries. Also you can add the required array of values to the (line series elements) to the respective LineSeries. You will need to set the AnchorType to Right for the Y-axis which you would like to place on the right side of the chart.
By default the X-axis labels will be added horizontally. If you would like to change the orientation then you can set the required angle to the X-axis labels.
float[] array1Array = new float[] { 2, 5, 6, 7 };
float[] array2Array = new float[] { 1, 6, 7, 9 };
float[] arrayAArray = new float[] { 5, 3, 8,1 };
float[] arrayBArray = new float[] { 6, 8, 3, 10 };
float[] arrayCArray = new float[] { 9, 5, 2, 7 };
float[] arrayDArray = new float[] { 10, 8, 2, 9 };
Chart chart = new Chart(0, 0, 500, 400);
PlotArea plotArea = chart.PrimaryPlotArea;
IndexedStackedLineSeriesElement seriesElement1 = new IndexedStackedLineSeriesElement("array1");
seriesElement1.Values.Add(array1Array);
IndexedStackedLineSeriesElement seriesElement2 = new IndexedStackedLineSeriesElement("array2");
seriesElement2.Values.Add(array2Array);
IndexedStackedLineSeriesElement seriesElement3 = new IndexedStackedLineSeriesElement("arrayA");
seriesElement3.Values.Add(arrayAArray);
IndexedStackedLineSeriesElement seriesElement4 = new IndexedStackedLineSeriesElement("arrayB");
seriesElement4.Values.Add(arrayBArray);
IndexedStackedLineSeriesElement seriesElement5 = new IndexedStackedLineSeriesElement("arrayC");
seriesElement5.Values.Add(arrayCArray);
IndexedStackedLineSeriesElement seriesElement6 = new IndexedStackedLineSeriesElement("arrayD");
seriesElement6.Values.Add(arrayDArray);
NumericYAxis leftYAxis = new NumericYAxis();
NumericYAxis rightYAxis = new NumericYAxis();
rightYAxis.AnchorType = YAxisAnchorType.Right;
IndexedStackedLineSeries lineSeries = new IndexedStackedLineSeries(rightYAxis);
lineSeries.Add(seriesElement1);
lineSeries.Add(seriesElement2);
IndexedStackedLineSeries lineSeries1 = new IndexedStackedLineSeries(leftYAxis);
lineSeries1.Add(seriesElement3);
lineSeries1.Add(seriesElement4);
lineSeries1.Add(seriesElement5);
lineSeries1.Add(seriesElement6);
plotArea.Series.Add(lineSeries);
plotArea.Series.Add(lineSeries1);
lineSeries.XAxis.Labels.Angle = 0;
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
page.Elements.Add(chart);
string output = @"C:\Temp\MyChart.pdf";
document.Draw(output);
Thanks,
ceTe Software Support Team