X Axes show both Top and Bottom

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v11)  /  Re: X Axes show both Top and Bottom

DynamicPDF CoreSuite for .NET (v11) Forum

 Sep 29 2021 6:11 AM
Hello, just want to ask if how will I put both top and bottom the xAxes with type HorizontalBar
I want it both the same, even I only have 1 bar.

Thanks
 Sep 29 2021 9:41 AM
Posted by a ceTe Software moderator
Hi,

You can achieve your requirements by creating a new NumericXAxis and adding it to the plot area. Make sure to set the AnchorType and correct Min and Max values for the Axis.

Here is a code sample to add top and bottom X-Axes:

            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);
            // Create a indexed bar series and add values to it
            IndexedBarSeries barSeries1 = new IndexedBarSeries("Website A");
            barSeries1.Values.Add(new float[] { 5 });
            // Add indexed bar series to the plot area
            plotArea.Series.Add(barSeries1);

            NumericXAxis customXAxis = new NumericXAxis();
            customXAxis.AnchorType = XAxisAnchorType.Top;
            customXAxis.Min = 0;
            customXAxis.Max = 5.5f;
            plotArea.XAxes.Add(customXAxis);

            // Create a title and add it to the xaxis
            Title lTitle = new Title("Visitors (in millions)");
            barSeries1.XAxis.Titles.Add(lTitle);

            //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
            string pdfFilePath = @"C:\Temp\MyChart.pdf";
            document.Draw(pdfFilePath);
           
Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 2:19 PM.