使用 Microsoft .NET Chart Controls Library 生成图像,无需控制 [英] Generate Image with Microsoft .NET Chart Controls Library without Control

查看:19
本文介绍了使用 Microsoft .NET Chart Controls Library 生成图像,无需控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不实例化 WinForm 或 ASP.NET Control 类的情况下使用 Microsoft Chart Controls 库生成图像(jpeg、png 等)?我见过的所有示例都使用了控制组件.我需要创建一个库,其中包含用于绘制数据并返回新图表图像的简单方法.示例:

Is it possible to generate images (jpeg, png, etc) using the Microsoft Chart Controls library without instantiating a WinForm or ASP.NET Control class? All the examples I have seen utilize a control component. I need to create a library which contains simple methods that take data to be plotted and returns a new chart image. Examples:

public byte[] GeneratePlot(IList<SeriesData> series)
{
    // generate and return JPEG
}
public void GeneratePlot(IList<SeriesData> series, Stream outputStream)
{
    // generate JPEG and write to stream
}

如果不可能:

  1. 你会推荐吗创建/处理新图表控制每次用户调用GeneratePlot() 方法?
  2. 在吗另一个 .NET 库(最好是免费)您会推荐吗?

谢谢

推荐答案

是的,这是可能的:

using System.Windows.Forms.DataVisualization.Charting;
using System.IO;
...
    public void GeneratePlot(IList<DataPoint> series, Stream outputStream) {
      using (var ch = new Chart()) {
        ch.ChartAreas.Add(new ChartArea());
        var s = new Series();
        foreach (var pnt in series) s.Points.Add(pnt);
        ch.Series.Add(s);
        ch.SaveImage(outputStream, ChartImageFormat.Jpeg);
      }
    }

这篇关于使用 Microsoft .NET Chart Controls Library 生成图像,无需控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆