注意添加引用Microsoft.Office.Interop.Owc11;//添加Office组件引用

void drawColumn3DOne(string[] xValue, string [] yValue, string chartTilte, string xTitle, string yTitle)
    {
        try
        {
            ii++;
            string strXdata = String.Empty;
            foreach (string strData in xValue)
            {
                strXdata += strData + "\t";
            }
            string strYdata = String.Empty;
            //为y轴中显示的点的x坐标指定特定的字符串,以便与x轴相对应
            foreach (string  strValue in yValue)
            {
                strYdata += strValue + "\t";
            }

            //创建ChartSpace对象来放置图表
            ChartSpace laySpace = new ChartSpaceClass();
            laySpace.Border.Color = "#B8B8B8";
            laySpace.HasChartSpaceTitle = true;
            laySpace.ChartSpaceTitle.Caption = chartTilte;
            laySpace.ChartSpaceTitle.Font.Bold = false;
            laySpace.ChartSpaceTitle.Font.Color = "blue";
            laySpace.ChartSpaceTitle.Font.Size = 14;

            //在ChartSpace对象中添加图表
            ChChart InsertChart = laySpace.Charts.Add(0);

            //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到
            InsertChart.Type = ChartChartTypeEnum.chChartTypeLineMarkers;//绘制曲线图
            InsertChart.PlotArea.BackWall.Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientHorizontal,
               ChartGradientVariantEnum.chGradientVariantCenter, "Silver", "white");//以双色渐变填充指定 ChInterior 对象。

            InsertChart.PlotArea.SideWall.Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientHorizontal,
               ChartGradientVariantEnum.chGradientVariantCenter, "Silver", "white");

            InsertChart.PlotArea.Floor.Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientHorizontal,
               ChartGradientVariantEnum.chGradientVariantCenter, "Silver", "white");

            //指定图表是否需要图例标注
            InsertChart.HasLegend = true;
            InsertChart.Legend.Font.Size = 9; // 图例的字体

            //3D设置
            InsertChart.GapDepth = 75;
            InsertChart.Inclination = 0;
            InsertChart.LightNormal = 0;
            InsertChart.Rotation = 0;

            //为x,y轴添加图示说明
            InsertChart.Axes[0].HasTitle = true;
            InsertChart.Axes[0].Title.Caption = xTitle;
            InsertChart.Axes[0].Title.Font.Size = 12;
            InsertChart.Axes[0].Font.Size = 9;
            InsertChart.Axes[0].Orientation = 0;

            InsertChart.Axes[1].HasTitle = true;
            InsertChart.Axes[1].Title.Caption = "沉降监测值(m)";
            InsertChart.Axes[1].Title.Font.Size = 12;
            InsertChart.Axes[1].MajorGridlines.Line.Color = "#B8B8B8";

            //添加一个series系列
            ChSeries objSeries = InsertChart.SeriesCollection.Add(0);
            objSeries.Interior.Color = "#67c3f0";
            objSeries.Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientDiagonalDown,
                ChartGradientVariantEnum.chGradientVariantCenter, "#67c3f0", "#dbf3ff");
            objSeries.Line.Color = "yellow";

            //给定名称
            objSeries.SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "沉降值");

            //给定分类
            objSeries.SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);

            //给定值
            objSeries.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);

            ChDataLabels dl = InsertChart.SeriesCollection[0].DataLabelsCollection.Add();


            //输出文件.
            string strAbsolutePath = (Server.MapPath("")) + "//ChartImages//" + "ShowDatao" + ii + ".gif";
            laySpace.ExportPicture(strAbsolutePath, "GIF", 600, 400);

            //创建GIF文件的相对路径.
            string strRelativePath = "./ChartImages/" + "ShowDatao" + ii + ".gif";

            //把图片添加到placeholder中,并在页面上显示
            string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
            this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));

        }
        catch (Exception ex)
        {
            Response.Redirect("http://www.cnblogs.com/errorpage.aspx?excp=" + ex.Message);
        }
    }

posted on 2010-04-28 20:24  linder  阅读(354)  评论(0)    收藏  举报