【问题标题】:Exporting OxyPlot chart to png in asp.net phoject在 asp.net phoject 中将 OxyPlot 图表导出为 png
【发布时间】:2017-12-09 13:53:59
【问题描述】:

我正在使用 asp.net 生成 pdf 文件。在pdf中我必须显示情节。我决定使用 oxyplot 将其导出为 png 并插入 pdf。文档说使用 PlotModel,用系列和轴填充它,然后使用 PngExporting 对象简单地导出。但是当我尝试生成它时,除了轴之外什么都没有显示。

我正在使用的代码:

var _plotModel = new OxyPlot.PlotModel()
            {
                PlotAreaBorderColor = OxyPlot.OxyColors.Transparent,
                LegendBorder = OxyPlot.OxyColors.Transparent,
                TitleToolTip = "Temperature",
                Culture = new System.Globalization.CultureInfo("ru-Ru"),
                Series =
                {
                    new OxyPlot.Series.LineSeries()
                    {
                        ItemsSource = new List<SimplePointModel>
                        {
                            new SimplePointModel {  Date = DateTime.Now, Temperature = 36.6f },
                            new SimplePointModel {  Date = DateTime.Now.AddDays(1), Temperature = 42.6f },
                            new SimplePointModel {  Date = DateTime.Now.AddDays(2), Temperature = 48.6f },
                        },
                        MarkerFill = OxyPlot.OxyColor.Parse("#A9CF9C"),
                        MarkerType = OxyPlot.MarkerType.Circle,
                        MarkerSize = item.ListSegments[0].Count() == 1 ? 2 : 1,
                        DataFieldX = "Date",
                        DataFieldY = "Temperature",
                        XAxisKey = "Date",
                        YAxisKey = "Temperature",
                        Color = OxyPlot.OxyColor.Parse("#A9CF9C"),
                    }
                },
                Axes =
                {
                    new OxyPlot.Axes.DateTimeAxis()
                    {
                        Position = OxyPlot.Axes.AxisPosition.Bottom,
                        Key = "Date",
                        ToolTip = "Temperature",
                        AbsoluteMinimum = OxyPlot.Axes.Axis.ToDouble(DateTime.Now.Date),
                        AbsoluteMaximum = OxyPlot.Axes.Axis.ToDouble(DateTime.Now.AddDays(10000))
                    },
                    new OxyPlot.Axes.LinearAxis()
                    {
                        Position = OxyPlot.Axes.AxisPosition.Left,
                        Key = "Temperature",
                        ToolTip = "Temperature",
                        IsZoomEnabled = false,
                        IsPanEnabled = false,
                    }
                }
            };
            using (var stream = System.IO.File.Create(Path.Combine(folder, "temp.png")))
            {
                PngExporter.Export(_plotModel, stream, 800, 400, OxyPlot.OxyColors.Transparent);
            }

我能做什么?

【问题讨论】:

  • DateTime.Now.AddDays(10000)?尝试像 10 天这样的值。我认为我可能是由 X 轴的比例引起的问题。
  • @kennyzx 我试着这样做,没有任何改变。它只是缩放属性。

标签: c# asp.net oxyplot


【解决方案1】:

我找到了解决方案:我们必须将数据加载到 Series 对象中的 Points 列表参数,而不是 ItemSource 参数。 ItemSource 参数用于移动版库。

【讨论】:

  • 为了完整起见,请在答案中添加解决方案的代码。
猜你喜欢
  • 1970-01-01
  • 2020-01-02
  • 2022-08-18
  • 1970-01-01
  • 1970-01-01
  • 2020-10-12
  • 2015-08-14
  • 2019-05-03
  • 2014-06-15
相关资源
最近更新 更多