Posted by a ceTe Software moderator
Hi,
Yes, you can add multiple Y-Axis to a chart . You will need to create respective YAxis objects and add them to YAxis list of the PlotArea.
Here is a code sample:
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
Chart chart = new Chart(0, 0, 400, 230);
PlotArea plotArea = chart.PrimaryPlotArea;
Title title1 = new Title("Website Visitors");
Title title2 = new Title("Year - 2007");
chart.HeaderTitles.Add(title1);
chart.HeaderTitles.Add(title2);
Indexed100PercentStackedColumnSeriesElement seriesElement1 = new Indexed100PercentStackedColumnSeriesElement("Website A");
seriesElement1.Values.Add(new float[] { 5, 7, 9, 6 });
Indexed100PercentStackedColumnSeriesElement seriesElement2 = new Indexed100PercentStackedColumnSeriesElement("Website B");
seriesElement2.Values.Add(new float[] { 4, 2, 5, 8 });
Indexed100PercentStackedColumnSeriesElement seriesElement3 = new Indexed100PercentStackedColumnSeriesElement("Website C");
seriesElement3.Values.Add(new float[] { 2, 4, 6, 9 });
AutoGradient autogradient1 = new AutoGradient(180f, CmykColor.Red, CmykColor.IndianRed);
seriesElement1.Color = autogradient1;
AutoGradient autogradient2 = new AutoGradient(180f, CmykColor.Green, CmykColor.YellowGreen);
seriesElement2.Color = autogradient2;
AutoGradient autogradient3 = new AutoGradient(180f, CmykColor.Blue, CmykColor.LightBlue);
seriesElement3.Color = autogradient3;
Indexed100PercentStackedColumnSeries columnSeries = new Indexed100PercentStackedColumnSeries();
columnSeries.Add(seriesElement1);
columnSeries.Add(seriesElement2);
columnSeries.Add(seriesElement3);
// Add series to the plot area
plotArea.Series.Add(columnSeries);
// Create a title and add it to the yaxis
Title lTitle = new Title("Visitors (in millions)");
columnSeries.YAxis.Titles.Add(lTitle);
// Create a custom Y-axis and add it to the list
PercentageYAxis customYAxis = new PercentageYAxis();
customYAxis.AnchorType = YAxisAnchorType.Right;
plotArea.YAxes.Add(customYAxis);
// Create a custom Y-axis and add it to the list
PercentageYAxis customYAxis1 = new PercentageYAxis(1);
customYAxis1.AnchorType = YAxisAnchorType.Floating;
plotArea.YAxes.Add(customYAxis1);
columnSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q1", 0));
columnSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q2", 1));
columnSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q3", 2));
columnSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q4", 3));
page.Elements.Add(chart);
string pdfFilePath = @"C:\Temp\ColumnChart.pdf";
document.Draw(pdfFilePath);
Thanks,
ceTe Software Support Team