can we add multiple charts on the same page?

can we add multiple charts on the same page?

Forum member · Aug 30, 2022
I am creating a new pdf and i am able to create one chat and display it on the page. However when i and creating second chart and try to give the different co-ordinates for 2nd chart, it is overlapping the 1st chart. Also i am not able to hide the legends.

Re: can we add multiple charts on the same page?

Support · Sep 2, 2022
Hi, Yes, you can add multiple charts to a single page using DynamicPDF Core Suite for .NET. You will need to set the calculated width and positions for the charts. Here is a code sample to add multiple charts and hiding legends. Document document = new Document(); Page page = new Page(); document.Pages.Add(page); float chartWidth = (page.Dimensions.Width - (page.Dimensions.LeftMargin + page.Dimensions.RightMargin)) / 2; Chart chartObj = new Chart(0, 0, chartWidth, 225); PlotArea plotAreaObj = chartObj.PrimaryPlotArea; XYScatterSeries xyScatterSeriesObj = new XYScatterSeries("Legend 1"); xyScatterSeriesObj.Values.Add(30, 0); xyScatterSeriesObj.Values.Add(25, 10); xyScatterSeriesObj.Values.Add(20, 15); xyScatterSeriesObj.Values.Add(15, 30); xyScatterSeriesObj.Values.Add(5, 40); xyScatterSeriesObj.LineDisplay = true; XYScatterSeries xyScatterSeriesObj1 = new XYScatterSeries("Legend 2"); float fakeX = 43.08f; float fakeY = 18.27f; xyScatterSeriesObj1.Values.Add(fakeY, fakeX); xyScatterSeriesObj1.Values.Add(10, 20); xyScatterSeriesObj1.LineDisplay = true; plotAreaObj.Series.Add(xyScatterSeriesObj1); plotAreaObj.Series.Add(xyScatterSeriesObj); Title titleTdh = new Title("Total Dynamic Head (ft.)"); Title titleGpm = new Title("Gallons Per Minute (gpm)"); xyScatterSeriesObj1.YAxis.Titles.Add(titleTdh); xyScatterSeriesObj1.XAxis.Titles.Add(titleGpm); chartObj.Legends[0].Visible = false; page.Elements.Add(chartObj); //SecondChart................................................. float xPos = chartObj.X + chartObj.Width; Chart chartObj2 = new Chart(xPos, 0, chartWidth, 225); PlotArea plotAreaObj2 = chartObj2.PrimaryPlotArea; XYScatterSeries xyScatterSeriesObj2 = new XYScatterSeries("Legend 4"); xyScatterSeriesObj2.Values.Add(30, 0); xyScatterSeriesObj2.Values.Add(25, 10); xyScatterSeriesObj2.Values.Add(20, 15); xyScatterSeriesObj2.Values.Add(15, 30); xyScatterSeriesObj2.Values.Add(5, 40); xyScatterSeriesObj2.LineDisplay = true; XYScatterSeries xyScatterSeriesObj3 = new XYScatterSeries("Legend 3"); float fakeX2 = 43.08f; float fakeY2 = 18.27f; xyScatterSeriesObj3.Values.Add(fakeY2, fakeX2); xyScatterSeriesObj3.Values.Add(10, 20); xyScatterSeriesObj3.LineDisplay = true; plotAreaObj2.Series.Add(xyScatterSeriesObj3); plotAreaObj2.Series.Add(xyScatterSeriesObj2); Title titleTdh2 = new Title("Total Dynamic Head (ft.)"); Title titleGpm2 = new Title("Gallons Per Minute (gpm)"); xyScatterSeriesObj3.YAxis.Titles.Add(titleTdh2); xyScatterSeriesObj3.XAxis.Titles.Add(titleGpm2); chartObj2.Legends[0].Visible = false; page.Elements.Add(chartObj2); page.Elements.Add(new LayoutGrid()); string output = @"C:\Temp\MyScatterChart.pdf"; document.Draw(output); Thanks, ceTe Software Support Team