OWC 绘图

OWC 绘图效果图:


引用:Microsoft Office Web Components 11.0
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop.Owc11;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.CreateChart();
    }

    /// <summary>
    /// 自定义柱状图的颜色。
    /// </summary>
    public void CreateChart()
    {
        //创建一个图形容器对象
        ChartSpace objCSpace = new ChartSpaceClass();
        //在图形容器中增加一个图形对象
        ChChart objChart = objCSpace.Charts.Add(0);
        //将图形的类型设置为柱状图的一种
        objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered3D;
        //旋转
        objChart.Rotation = 25;//表示指定三维图表的旋转角度
        objChart.Inclination = 0;//表示指定三维图表的视图斜率。有效范围为 -90 到 90

        ChBorder border = objCSpace.Border;
        border.set_Weight(LineWeightEnum.owcLineWeightMedium);

        //显示标题
        objChart.HasTitle = true;
        //设置标题内容
        objChart.Title.Caption = "Test";
        objChart.Title.Font.Color = "#1a3b69";
        objChart.Title.Font.Size = 10;
        objChart.Title.Font.Bold = true;
        objChart.Title.Font.Name = "Verdana";
        //显示图例
        objChart.HasLegend = false;

        //在图形对象中添加一个系列
        objChart.SeriesCollection.Add(0);
        //给定系列的名字
        objChart.SeriesCollection[0].SetData (ChartDimensionsEnum.chDimSeriesNames,
            + (int)ChartSpecialDataSourcesEnum.chDataLiteral, "指标");
        //给定值
        objChart.SeriesCollection[0].SetData (ChartDimensionsEnum.chDimValues,
            + (int)ChartSpecialDataSourcesEnum.chDataLiteral, "10\t40\t58\t55\t44");
       
        //将柱状图的第一条柱设置为红色
        //Point:代表图中的一部分,比如柱图的一条柱,饼图的一个扇区
        //Interior:表示指定对象的内部
        //objChart.SeriesCollection[0].Points[0].Interior.Color = "#578423";
        //objChart.SeriesCollection[0].Points[0].Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientDiagonalDown, ChartGradientVariantEnum.chGradientVariantEnd, "Blue", "White");
        objChart.SeriesCollection[0].Interior.Color = "#5698f0";
        objChart.SeriesCollection[0].Border.DashStyle = ChartLineDashStyleEnum.chLineSolid;
        objChart.SeriesCollection[0].Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientFromCorner, ChartGradientVariantEnum.chGradientVariantStart, "#5699f0", "#a2c7f7");
        objChart.SeriesCollection[0].Border.Color = "#536e92";
        //objChart.PlotArea.Interior.Color = ChartColorIndexEnum.chColorNone;
        objChart.PlotArea.Interior.Color = "#DCEAFC";
        objChart.Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientFromCorner, ChartGradientVariantEnum.chGradientVariantStart, "#d5e0f1", "#fdfefe");
        objChart.Border.Color = "#1a3b69";

        objChart.PlotArea.Border.Color = "#b1b9c6";
        for (int i = 0; i < objChart.Axes.Count; i++)
        {
            //objChart.Axes[i].MajorGridlines.Line.Color = "#E6E6E6";
            //objChart.Axes[i].MajorGridlines.Line.DashStyle = ChartLineDashStyleEnum.chLineSquareDot;
            //objChart.Axes[i].MajorGridlines.Line.Miter = ChartLineMiterEnum.chLineMiterBevel;
            objChart.Axes[i].HasMajorGridlines = true;
            objChart.Axes[i].HasMinorGridlines = false;
            //objChart.Axes[i].Line.Color = "#b1b9c6";
            objChart.Axes[i].Line.Color = "#b1b9c6";
            objChart.Axes[i].MajorGridlines.Line.Color = "#b1b9c6";
            objChart.Axes[i].Font.Name = "Verdana";
            objChart.Axes[i].Font.Size = 8;
            objChart.Axes[i].Font.Color = "#000022";
        }

        //显示数据,创建GIF文件的相对路径.
        //string FileName = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".gif";
        string strAbsolutePath = (Server.MapPath(".")) + "\\showdata3.gif";
        objCSpace.ExportPicture(strAbsolutePath, "GIF", 450, 300);
        Image1.ImageUrl = "./ShowData3.gif";
    }

}

你可能感兴趣的:(绘图)