使用Microsoft.Office.Interop.Owc11进行绘图





using Microsoft.Office.Interop.Owc11;  导入命名空间



//使用Microsoft.Office.Interop.Owc11进行绘图

    protected void GetDistrictSales(string getDate)

    {

        DataSet ds = admin.GetDistrictReg(getDate);

        GridView1.DataSource = ds.Tables["GetDistrictReg"];

        GridView1.DataBind();

        //DataList1.DataSource = ds.Tables["GetDistrictReg"];

        //DataList1.DataBind();

        string x = "";

        string y = "";

        //string file;

        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)

        {

            x = ds.Tables["GetDistrictReg"].Rows[0]["d_districtName"].ToString();

            y = ds.Tables["GetDistrictReg"].Rows[0]["coun"].ToString();

            for (int i = 1; i < ds.Tables[0].Rows.Count; i++)

            {

                x += '/t' + ds.Tables[0].Rows[i]["d_districtName"].ToString();

                y += '/t' + ds.Tables[0].Rows[i]["coun"].ToString();

            }



            //创建ChartSpace对象来放置图表

            ChartSpace objCSpace = new ChartSpaceClass();



            //在ChartSpace对象中添加图表,Add方法返回chart对象

            ChChart objChart = objCSpace.Charts.Add(0);



            //指定图表的类型。类型由ChartChartTypeEnum枚举值得到

            objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;



            //设置两柱之间的间距,数值越大柱子越细

            objChart.GapWidth = 500;





            //指定图表是否需要图例

            objChart.HasLegend = true;



            //给定标题

            objChart.HasTitle = true;

            objChart.Title.Caption = getDate + "各地区报名人数汇总";



            //给定x,y轴的图示说明

            //x轴

            objChart.Axes[0].HasTitle = true;

            objChart.Axes[0].Title.Caption = "X : 区域: ";//+ danwei;

            objChart.Axes[0].Title.Font.Size = 12;

            objChart.Axes[0].Title.Font.Color = "blue";

            objChart.Axes[0].Font.Size = 10;

            objChart.Axes[0].Font.Bold = true;





            //y轴

            objChart.Axes[1].HasTitle = true;

            objChart.Axes[1].Title.Caption = "Y : ";

            objChart.Axes[1].Title.Font.Color = "blue";

            objChart.Axes[1].Title.Font.Size = 12;

            objChart.Axes[1].Font.Size = 10;

            objChart.Axes[1].Font.Bold = true;





            // objChart.SeriesCollection[1].DataLabelsCollection[0].HasValue = true;

            //objChart.SeriesCollection[1].DataLabelsCollection.Add();



            //计算数据

            /*categories 和 values 可以用tab分割的字符串来表示*/

            //string strSeriesName = "图例 1";



            //添加一个series

            objChart.SeriesCollection.Add(0);



            //给定series的名字

            //objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);



            //给定分类

            objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, x);



            //给定值

            objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, y);



            //给每个柱子上绑定数据

            objChart.SeriesCollection[0].DataLabelsCollection.Add();            

            //是否绑定名称

            objChart.SeriesCollection[0].DataLabelsCollection[0].HasCategoryName = false;

            //设置柱子的字体大小以及颜色

            objChart.SeriesCollection[0].DataLabelsCollection[0].Font.Size = 10;

            objChart.SeriesCollection[0].DataLabelsCollection[0].Font.Bold = true;



            //输出成GIF文件.

            //file = "/" + Guid.NewGuid().ToString() + ".gif";            

            string strAbsolutePath = (Server.MapPath(".")) + "//ShowData1.gif";



            //file = Guid.NewGuid().ToString() + ".gif";

            //string strAbsolutePath = (Server.MapPath(".")) + "//" + file;



            objCSpace.ExportPicture(strAbsolutePath, "GIF", 780, 350);

            Image1.Visible = true;

            



        }

        else

        {

            //file = "/images/0.gif";

            Image1.Visible = false;

            

        }

    }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值