生成和Microsoft .NET图表图像控件库没有控制 [英] Generate Image with Microsoft .NET Chart Controls Library without Control
本文介绍了生成和Microsoft .NET图表图像控件库没有控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能生成使用Microsoft图表控件库图像(JPEG,PNG等),而不实例化一个WinForm或ASP.NET控件类?我见过的所有示例利用控制组件。我需要创建一个包含简单的方法,即采取数据绘制,并返回一个新的图表图像库。例如:
公共字节[] GeneratePlot(IList的< SeriesData>系列)
{
//生成并返回JPEG
}
公共无效GeneratePlot(IList的< SeriesData>系列,流的OutputStream)
{
//生成JPEG和写入流
}
如果这是不可能的:
<醇>
创建/每个用户调用
GeneratePlot()方法?
时间设置一新的图表
控制
,你会推荐其他.NET库(最好是
免费)?
感谢
解决方案
是的,这是可能的:
使用System.Windows.Forms.DataVisualization.Charting;
:使用System.IO;
...
公共无效GeneratePlot(IList的<&数据点GT;系列,流的OutputStream){使用
(VAR CH =新图()){
ch.ChartAreas.Add(新ChartArea());
变种S =新系列();
的foreach(串联VAR PNT)s.Points.Add(PNT);
ch.Series.Add(S);
ch.SaveImage(OutputStream的,ChartImageFormat.Jpeg);
}
}
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
}
If it is not possible:
- would you recommend creating/disposing a new chart control each time the user calls the GeneratePlot() method?
- is there another .NET library (preferably free) that you would recommend?
Thanks
解决方案
Yes, that's possible:
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图表图像控件库没有控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文