OWC 绘制3D柱状图

来源:互联网 发布:linux性能监控 知乎 编辑:程序博客网 时间:2024/05/17 12:50




引用:Microsoft Office Web Components 11.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
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 test : System.Web.UI.Page

{
    protected void Page_Load(object sender, EventArgs e)
    {
        //创建ChartSpace对象来放置图表  图形容器对象
        ChartSpace laySpace = new ChartSpaceClass();

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

        //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到
        //InsertChart.Type = ChartChartTypeEnum.chChartTypeLine;//折线图
        //InsertChart.Type = ChartChartTypeEnum.chChartTypeArea;//面积图
        //InsertChart.Type = ChartChartTypeEnum.chChartTypeBarClustered;//条形图
        InsertChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered3D;//柱形图
        //InsertChart.Border.Color = "White";//图像的边框颜色

        //旋转
        InsertChart.Rotation = 5;//表示指定三维图表的旋转角度
        InsertChart.Inclination = 0;//表示指定三维图表的视图斜率。有效范围为 -90 到 90

        laySpace.Border.Color = "white";
        
        //指定图表是否需要图例标注
        InsertChart.HasLegend = true;
        InsertChart.Legend.Font.Size = 10;//字体
        InsertChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;//图例标注的位置


        //图表的标题
        InsertChart.HasTitle = true;//为图表添加标题
        InsertChart.Title.Font.Color = "#1a3b69";//颜色
        InsertChart.Title.Caption = "智商比例";//设置标的内容
        InsertChart.Title.Font.Size = 15;//设置标题字体大小
        InsertChart.Title.Font.Bold = true;//是否加粗
        InsertChart.Title.Font.Name = "Verdana";//字体

        //为x,y轴添加图示说明
        InsertChart.Axes[0].HasTitle = true;
        InsertChart.Axes[0].Title.Caption = "2015.9.25";//月份

        InsertChart.Axes[1].HasTitle = true;
        InsertChart.Axes[1].Scaling.SplitMinimum = 200;
        InsertChart.Axes[1].Title.Caption = "智商高低";

        //添加一个series系列
        InsertChart.SeriesCollection.Add(0);

        //给定系列的名字
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames,
            +(int)ChartSpecialDataSourcesEnum.chDataLiteral, "啊哈哈");
        //给定值
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
            +(int)ChartSpecialDataSourcesEnum.chDataLiteral, "10\t40\t58\t55\t44");

        //将柱状图的第一条柱设置为红色
        //Point:代表图中的一部分,比如柱图的一条柱,饼图的一个扇区
        //Interior:表示指定对象的内部
        InsertChart.SeriesCollection[0].Interior.Color = "#5698f0";
        InsertChart.SeriesCollection[0].Border.DashStyle = ChartLineDashStyleEnum.chLineSolid;
        InsertChart.SeriesCollection[0].Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientFromCorner, ChartGradientVariantEnum.chGradientVariantStart, "#5699f0", "#a2c7f7");
        InsertChart.SeriesCollection[0].Border.Color = "#536e92";
        
        InsertChart.PlotArea.Interior.Color = "#DCEAFC";
        //底色
        //InsertChart.Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientFromCorner, ChartGradientVariantEnum.chGradientVariantStart, "#d5e0f1", "#fdfefe");
        
        InsertChart.PlotArea.Border.Color = "#b1b9c6";
        for (int i = 0; i < InsertChart.Axes.Count; i++)
        {
            InsertChart.Axes[i].MajorGridlines.Line.Color = "#E6E6E6";
            InsertChart.Axes[i].MajorGridlines.Line.DashStyle = ChartLineDashStyleEnum.chLineSquareDot;
            InsertChart.Axes[i].MajorGridlines.Line.Miter = ChartLineMiterEnum.chLineMiterBevel;
            
            InsertChart.Axes[i].HasMajorGridlines = true;
            InsertChart.Axes[i].HasMinorGridlines = false;
            
            InsertChart.Axes[i].Line.Color = "#b1b9c6";
            InsertChart.Axes[i].MajorGridlines.Line.Color = "#b1b9c6";
            InsertChart.Axes[i].Font.Name = "Verdana";
            InsertChart.Axes[i].Font.Size = 8;
            InsertChart.Axes[i].Font.Color = "#000022";
        }


        string strAbsolutePath = (Server.MapPath(".")) + "/Data/test/ShowData.gif";

        laySpace.ExportPicture(strAbsolutePath, "GIF", 900, 400);

        //创建GIF文件的相对路径.
        string strRelativePath = "./Data/test/ShowData.gif";

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

    }
0 0
原创粉丝点击