I am currently working on a line series graph using IndexedStackedLineSeriesElement class. I would like to have 2 yaxis. One at the right and another at the left of the chart.Is there a way to do this?
Secondly Is there a way to make my x-axis label display horizontally instead of vertically?
Below is my curerent code
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.AddarrayCArray);
IndexedStackedLineSeriesElement seriesElement6 = new IndexedStackedLineSeriesElement(arrayD);
seriesElement6.Values.Add(arrayDArray);
IndexedStackedLineSeries lineSeries = new IndexedStackedLineSeries();
lineSeries.Add(seriesElement1);
lineSeries.Add(seriesElement2);
lineSeries.Add(seriesElement3);
lineSeries.Add(seriesElement4);
lineSeries.Add(seriesElement5);
lineSeries.Add(seriesElement6);
plotArea.Series.Add(lineSeries);
I would like array1 and array 2 to be plotted for the right y axis and arrayA, arrayB, arrayC and arrayD to be plotted for the left y axis.
Two Y axes and Horizontal X-axes label
Re: Two Y axes and Horizontal X-axes label
Support · Sep 26, 2019Hello,
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
Re: Two Y axes and Horizontal X-axes label
Forum member · Sep 26, 2019Thank you. This response was very helpful. In my application the x axis label shows vertically due to the authomatic wraptext. I want to know if there is a way to force it to display horizontally. I don't want to make wraptext false because I need the whole values to display.
It shows up like this:
HH
:
MM
:
SS
I want it to show up like this :
HH:MM:SS.
Thank you once again.
Re: Two Y axes and Horizontal X-axes label
Support · Sep 27, 2019Hello,
It looks like the default width set for the X-axis label is not sufficient to fit the text in one line and hence it is wrapping to new lines. Please try setting the MaximumLabelWidth for the X-axis labels accordingly to fit the text in one line and see it works for you. Below is a line of code.
lineSeries.XAxis.Labels.MaximumLabelWidth = 100;
Thanks,
ceTe Software Support Team
Re: Two Y axes and Horizontal X-axes label
Forum member · Sep 27, 2019Hi, thanks for the response. However "MaximumLabelWidth" property is not available in this version. Is there any other property or function I can use to achieve this? Thank you
Re: Two Y axes and Horizontal X-axes label
Support · Sep 27, 2019Hello,
This feature is included in version 8.0.4 and later of the DynamicPDF product. If you are using an older version, it is not possible to set the width of the X-axis label.
You can download fully functional evaluation edition of DynamicPDF product here
.
Thanks,
ceTe Software Support Team
Re: Two Y axes and Horizontal X-axes label
Forum member · Sep 27, 2019Thank you