how to add only 2 gridlines in a barchart

how to add only 2 gridlines in a barchart

Forum member · Mar 10, 2015
Hi, I have created a bar graph in the PDF document. I want to show only two gridlines one after 25th position and another after 75th position but I am unable to draw the gridlines as it is drawn after a fixed interval like(0,25,50,75,100). but I need gridlines to appear only for 25 and 75. Please assist.

Re: how to add only 2 gridlines in a barchart

Support · Mar 11, 2015
Hello, It is not possible to apply grid lines only for the specified intervals (at 25th and 75th position) on X and Y axis using DynamicPDF Generator for .NET product. You can add the major grid lines for all the X and Y axis values or set the interval for the grid line and below is the code for it. // Create a PDF Document Document document = new Document(); // Create a Page and add it to the document Page page = new Page(); document.Pages.Add(page); // Create a chart Chart chart = new Chart(0, 0, 400, 230); // Create a plot area PlotArea plotArea = chart.PrimaryPlotArea; // Create header titles and add it to the chart Title title1 = new Title("Website Visitors"); Title title2 = new Title("Year 2007"); chart.HeaderTitles.Add(title1); chart.HeaderTitles.Add(title2); // Create a indexed bar series and add values to it IndexedBarSeries barSeries1 = new IndexedBarSeries("Website A"); barSeries1.Values.Add(new float[] { 5, 7, 9, 6 }); IndexedBarSeries barSeries2 = new IndexedBarSeries("Website B"); barSeries2.Values.Add(new float[] { 4, 2, 5, 8 }); IndexedBarSeries barSeries3 = new IndexedBarSeries("Website C"); barSeries3.Values.Add(new float[] { 2, 4, 6, 9 }); // Add indexed bar series to the plot area plotArea.Series.Add(barSeries1); plotArea.Series.Add(barSeries2); plotArea.Series.Add(barSeries3); // Create a title and add it to the xaxis Title lTitle = new Title("Visitors (in millions)"); barSeries1.XAxis.Titles.Add(lTitle); //Adding grid lines by specifying the intervals. XAxisGridLines xGridLines = new XAxisGridLines(2); barSeries1.XAxis.MajorGridLines = xGridLines; //Adding AxisLabels to the yAxis barSeries1.YAxis.Labels.Add(new IndexedYAxisLabel("Q1", 0)); barSeries1.YAxis.Labels.Add(new IndexedYAxisLabel("Q2", 1)); barSeries1.YAxis.Labels.Add(new IndexedYAxisLabel("Q3", 2)); barSeries1.YAxis.Labels.Add(new IndexedYAxisLabel("Q4", 3)); // Add the chart to the page page.Elements.Add(chart); // Save the PDF document.Draw(@"C:/Temp/MyDocument.pdf"); Thanks, ceTe Software Support Team.

Re: how to add only 2 gridlines in a barchart

Forum member · Mar 12, 2015
Thanks for the code sample. I have already seen this code in the example documents but this is not my requirement.

Re: how to add only 2 gridlines in a barchart

Support · Mar 12, 2015
Hello, It is not possible to add only two grid lines on either X or Y axis on bar chart using DynamicPDF Generator for .NET API. The DynamicPDF API will add grid lines for all X or Y Axis values or at specified intervals. Thanks, ceTe Software Support Team.