保存图像列表中创建的图表

时间:2022-08-07 00:22:56

I have created charts dynamically but I want to save chart created in image list or any other types of lists, as long as is not in folder.

我已动态创建图表但我想保存在图像列表或任何其他类型的列表中创建的图表,只要不在文件夹中。

Question: How to save chart created in image list/other type of list?

问题:如何保存图像列表/其他类型列表中创建的图表?

This is my codes:

这是我的代码:

                        Chart Chart1 = new Chart();
                        Chart1.DataSource = dt;
                        Chart1.Width = 800;
                        Chart1.Height = 500;

                        Chart1.Series.Add(new Series());
                        Chart1.Series[0].ChartType = SeriesChartType.BoxPlot;

                        List<object> List_CHART = dt.AsEnumerable().ToList<object>();

                        foreach (DataRow row in dt.Rows)
                        {
                            Chart1.Series[0].Points.AddXY(row["TITLE"], new object[] { row["MIN"], row["MAX"], row["25TH_PERCENTILE"], row["75TH_PERCENTILE"], row["50TH_PERCENTILE"], row["AVG"] });
                        }

                        //create chartareas
                        ChartArea ca= new ChartArea();
                        ca.AxisX = new Axis();
                        ca.AxisY = new Axis();
                        Chart1.ChartAreas.Add(ca);

                        //databind
                        Chart1.DataBind();
                        Chart1.Visible = true;

                        panel.Controls.Add(Chart1);

Thanks.

1 个解决方案

#1


0  

  1. Look at Chart API to find Chart.SaveImage Method.
  2. 查看Chart API以查找Chart.SaveImage方法。

  3. Google 'save Chart to stream' to find this SO question.
  4. 谷歌“保存图表流”来找到这个问题。

  5. Look at Image API Image.FromStream Method
  6. 查看Image API Image.FromStream方法

The final solution should look something like this:

最终的解决方案应该是这样的:

        var chartImages = new ImageList();
        var chartStream = new MemoryStream()
        chart.SaveImage(chartStream, ChartImageFormat.Png);
        var chartImage = Image.FromStream(chartStream);
        chartImages.Add(chartImage);

Also, Pay attention to Remarks section on Image class:

另外,请注意Image类的备注部分:

You must keep the stream open for the lifetime of the Image.

您必须在图像的生命周期内保持流打开。

#1


0  

  1. Look at Chart API to find Chart.SaveImage Method.
  2. 查看Chart API以查找Chart.SaveImage方法。

  3. Google 'save Chart to stream' to find this SO question.
  4. 谷歌“保存图表流”来找到这个问题。

  5. Look at Image API Image.FromStream Method
  6. 查看Image API Image.FromStream方法

The final solution should look something like this:

最终的解决方案应该是这样的:

        var chartImages = new ImageList();
        var chartStream = new MemoryStream()
        chart.SaveImage(chartStream, ChartImageFormat.Png);
        var chartImage = Image.FromStream(chartStream);
        chartImages.Add(chartImage);

Also, Pay attention to Remarks section on Image class:

另外,请注意Image类的备注部分:

You must keep the stream open for the lifetime of the Image.

您必须在图像的生命周期内保持流打开。