c#中teechart生成的图表导出

string url1 = Server.MapPath("~//ChartImage//") + "chart1.jpg";
string url2 = Server.MapPath("~//ChartImage//") + "chart2.jpg";
       if (ds1.Tables[0].Rows.Count > 0)
       {
            for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
            {
               ch1 = this.WebChart2.Chart;
               ch1.Series.RemoveAllSeries();

                for (int j = 1; j < p_colArray.Length; j++)
                {
                  Steema.TeeChart.Styles.Bar _bar = new Steema.TeeChart.Styles.Bar();

                    _bar.DataSource = ds1.Tables[0];
                    _bar.Title = GetLabel(p_colArray[j]);
                    _bar.XValues.DataMember = "CJSJ";
                    _bar.XValues.DateTime = true;

                    _bar.YValues.DataMember = p_colArray[j];
                    ch1.Series.Add(_bar);
                     ch1.Export.Image.JPEG.Save(url2);

                     }
               }
               for (int ii = 0; ii < ds1.Tables[0].Rows.Count; ii++)
               {
                ch2 = this.WebChart1.Chart;
                ch2.Series.RemoveAllSeries();
                for (int z = 1; z < p_colArray.Length; z++)
                {
                 Steema.TeeChart.Styles.FastLine _line = new Steema.TeeChart.Styles.FastLine();
                  _line.XValues.DataMember = "CJSJ";
                  _line.XValues.DateTime = true;
                  _line.DataSource = ds1.Tables[0];
                  _line.Title = GetLabel(p_colArray[z]);
                  _line.YValues.DataMember = p_colArray[z];
                  ch2.Series.Add(_line);
                  ch2.Export.Image.JPEG.Save(url1);
                  }
                 }
            }

 

 protected void btnChartExport1_Click(object sender, EventArgs e)
    {
        FileInfo file = new FileInfo(Server.MapPath("~/ChartImage/chart1.jpg"));
        if (file.Exists)
        {
            FileDownload(Server.MapPath("~/ChartImage/chart1.jpg"));
        }
        else
        {
            Response.Write("");
        }
    }
    protected void btnChartExport2_Click(object sender, EventArgs e)
    {
        FileInfo file = new FileInfo(Server.MapPath("~/ChartImage/chart2.jpg"));
        if (file.Exists)
        {
            FileDownload(Server.MapPath("~/ChartImage/chart2.jpg"));
        }
        else
        {
            Response.Write("");
        }
    }
    private void FileDownload(string FullFileName)
    {
        FileInfo DownloadFile = new FileInfo(FullFileName);
        FileInfo file1 = new FileInfo(Server.MapPath("~/ChartImage/chart1.jpg"));
        FileInfo file2 = new FileInfo(Server.MapPath("~/ChartImage/chart2.jpg"));
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
        Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
        Response.WriteFile(DownloadFile.FullName);
        if (file1.Exists)//删除保存到服务器上的图片
        {
            file1.Delete();
        }
        if (file2.Exists)
        {
            file2.Delete();
        }
        Response.Flush();
        Response.End();
        Response.Close();
    }

你可能感兴趣的:(c#)