我有一个条形图,其中包含与公司相关的各种机器的信息。
基本上我想将此图表输出到 png 文件,但我似乎无法正确输出。
我已经在谷歌上搜索了几个小时试图找到一个好的教程,但他们中的大多数人使用奇怪的第三方组件来下载图像,我真的不想这样做。
这是我目前的代码:
string tmpChartName = "/MachinesByCompanyChart.png";
protected void GenerateBarChartBut_click(object sender, EventArgs e)
{
Chart1.Visible = false;
Chart2.Visible = true;
DataTable table = new DataTable();
dal.getTotalAssetsByCompany("table", TAB1CompanyDDL.SelectedItem.Text);
table = dal.Results.Tables["table"];
DataView dv = table.DefaultView;
Chart2.Series["Series1"].Points.DataBindXY(dv, "AssetType", dv, "Total");
Chart2.Palette = ChartColorPalette.None;
Chart2.PaletteCustomColors = myGreenColorPalette;
string imgPath2 = Server.MapPath(tmpChartName);
Chart2.SaveImage(imgPath2, ChartImageFormat.Png);
}
protected void ExportAssetsByCompanyBut_click(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = Chart1.ImageType.ToString();
Response.AddHeader("Content-Disposition", "attachment; filename=" + tmpChartName);
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
string headerTable = @"";
Response.Write(headerTable);
Response.Write(stringWrite.ToString());
Response.End();
}
我是否正确地将保存的图像传递给 writer 方法?