This repository was archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
This repository was archived by the owner on Sep 9, 2024. It is now read-only.
Set line chart x values on major gridlines #13
Copy link
Copy link
Open
Description
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");
But I expected the red line and the red lettering (drawn by hand):
How can I implement this? Is that even possible? Many thanks.
Metadata
Metadata
Assignees
Labels
No labels

