Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Set line chart x values on major gridlines #13

Open
alipiriyaie opened this issue Mar 2, 2021 · 0 comments
Open

Set line chart x values on major gridlines #13

alipiriyaie opened this issue Mar 2, 2021 · 0 comments

Comments

@alipiriyaie
Copy link

alipiriyaie commented Mar 2, 2021

I have tried now to set the x-values for a line statistic to the major gridlines. But this does not work. This is how I try it in a ASP.NET MVC application:

        var doc = new PdfDocument();
        var page = doc.AddPage();
        page.Orientation = PdfSharp.PageOrientation.Landscape;
        page.Size = PdfSharp.PageSize.A4;

        var gfx = XGraphics.FromPdfPage(page);

        var chart = new Chart();
        chart.Type = ChartType.Line;

        chart.YAxis.MajorTickMark = TickMarkType.Outside;
        chart.YAxis.LineFormat.Color = XColors.Black;
        chart.YAxis.LineFormat.Width = 0.5;
        chart.YAxis.LineFormat.Visible = true;
        chart.YAxis.TickLabels.Format = "0";

        chart.XAxis.MajorTickMark = TickMarkType.None;
        chart.XAxis.MinorTickMark = TickMarkType.Outside;
        chart.XAxis.LineFormat.Color = XColors.Black;
        chart.XAxis.LineFormat.Width = 0.5;
        chart.XAxis.LineFormat.Visible = true;
        chart.XAxis.MajorTick = 0.0;
        chart.XAxis.MinorTick = 0.0;
        chart.XAxis.HasMajorGridlines = false;
        chart.XAxis.HasMinorGridlines = false;
        


        var series = chart.SeriesCollection.AddSeries();
        var yValues = new int[]{ 0, 5, 3, 6, 7 };
        series.HasDataLabel = true;
        chart.PlotArea.LineFormat.Width = 1;

        var xseries = chart.XValues.AddXSeries();
                    
        for(var i = 0; i < yValues.Length; i++)
        {
            series.Add(yValues[i]);
            xseries.Add("abc");
        }

        series.LineFormat.Color = XColors.Orange;
        series.MarkerStyle = MarkerStyle.None;
        series.LineFormat.Width = 5;

        chart.PlotArea.FillFormat.Color = XColors.White;

        var chartFrame = new ChartFrame();
        chartFrame.Location = new XPoint(20, 80);
        chartFrame.Size = new XSize(400, 400);
        chartFrame.Add(chart);

        chartFrame.DrawChart(gfx);

        var ms = new MemoryStream();
        doc.Save(ms);
        var fileBytes = ms.ToArray();
        ms.Close();

        return File(fileBytes, "application/pdf", "filename.pdf");

This is what I get:
image

But I expected the red line and the red lettering (drawn by hand):

image

How can I implement this? Is that even possible? Many thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant