惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
I
InfoQ
B
Blog RSS Feed
D
DataBreaches.Net
S
SegmentFault 最新的问题
P
Proofpoint News Feed
A
About on SuperTechFans
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
小众软件
小众软件
博客园 - Franky
有赞技术团队
有赞技术团队
D
Docker
T
Tailwind CSS Blog
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
V
Visual Studio Blog
宝玉的分享
宝玉的分享
爱范儿
爱范儿

博客园 - 佚名

SqlCommand执行带GO的SQL脚本文件 TreeList之Extjs篇 XtreTreeList使用扎记(四) TreeList使用扎记(3) XtraTreeList使用扎记(2) TreeView节点快速访问之道 看了感触很深的一个贴子 XtraTreeList使用扎记(1) 勇气宣言 搞笑的段子 特别的一天 C#设计模式读书笔记之合成模式 C#设计模式读书笔记之适配器模式 C#设计模式读书笔记(1) Vs2003多窗口下的复杂数据传递 男人25岁前必须明白的21个道理!!! 关于Excel中Merge单元格 NET下XML的访问 ADO.NET技术内幕疑点之一
OWC中双刻度图表的实现
佚名 · 2006-05-24 · via 博客园 - 佚名

前几天给一位朋友解决一个OWC的问题,开始一年难度倒是没有什么,就接下来了。第二天给她答复。待自已动手以后。才感到这个问题非常棘手。要求是生成"线—柱图",这个类型在OWC 的ChartChartTypeEnum枚举类型中是不存在的。这一下可傻了眼,感到无从下手了。不停的尝试,不停的找资料,哎,承诺的后果还真严重,折腾了近四个小时。终于有点眉目,不给整个Chart 对象指定类型,给表下的Series对象指定类型,先用一个Series对象画出柱图,然后再加入一个Series对象。指定类型为线型。问题解决。代码如下:

using Microsoft.Office.Interop;
using OWC= Microsoft.Office.Interop.Owc11;
public partial class Default212 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //创建ChartSpace对象来放置图表
        OWC.ChartSpace objCSpace = new OWC.ChartSpaceClass();

        //是否显示图例
        objCSpace.HasChartSpaceLegend = true;

        //在ChartSpace对象中添加图表,Add方法返回chart对象
        OWC.ChChart objChart = objCSpace.Charts.Add(0);

        //指定图为柱形图
   

        //给定标题
        objChart.HasTitle = true;
        objChart.Title.Caption = "上半年分布图";

        //给定x,y轴的图示说明
        objChart.Axes[0].HasTitle = true;
        objChart.Axes[0].Title.Caption = "Y : 数量";
        objChart.Axes[1].HasTitle = true;
        objChart.Axes[1].Title.Caption = "X : 月份";

        //计算数据
        /*categories 和 values 可以用tab分割的字符串来表示*/
        string strSeriesName = "我的测试";
        string strSeriesName1 = "LAR";
        string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t' + "4" + '\t' + "5" + '\t' + "6" + '\t';
        string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t' + "10" + '\t' + "12" + '\t' + "6" + '\t';
        string strValue1 = "0.038%" + '\t' + ".034%" + '\t' + ".039%" + '\t' + ".036%" + '\t' + ".040%" + '\t' + ".033%" + '\t';

        /*柱形图*/
        //添加一个series
        objChart.SeriesCollection.Add(0);
        objChart.SeriesCollection[0].Type = OWC.ChartChartTypeEnum.chChartTypeColumnClustered;
        //给定series的名字
        objChart.SeriesCollection[0].SetData(OWC.ChartDimensionsEnum.chDimSeriesNames,
            +(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);

        //给定分类
        objChart.SeriesCollection[0].SetData(OWC.ChartDimensionsEnum.chDimCategories,
            +(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);

        //给定objChart[0]的值
        OWC.ChSeries sDispDppm = objChart.SeriesCollection[0];
        sDispDppm.SetData
            (OWC.ChartDimensionsEnum.chDimValues,
            (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);

        /*折线图*/
        //再增加一个Series
       
        OWC.ChSeries sDispLar = objChart.SeriesCollection.Add(0);
        sDispLar.Ungroup(true);
        OWC.ChAxis MyAxis = objChart.Axes.Add(sDispLar.get_Scalings(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues));
        MyAxis.Position = OWC.ChartAxisPositionEnum.chAxisPositionRight;
        MyAxis.HasMinorGridlines = false;
        MyAxis.NumberFormat = "0.00%";
        MyAxis.HasTitle = true;
        MyAxis.Title.Caption = "报废率(%)";
        //给定series的名字
        sDispLar.SetData(OWC.ChartDimensionsEnum.chDimSeriesNames,
            +(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName1);

        //给定objChart[1]的值
        sDispLar.SetData
            (OWC.ChartDimensionsEnum.chDimValues,
            (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strValue1);

        //Ungroup series
        sDispLar.Type = OWC.ChartChartTypeEnum.chChartTypeLineMarkers;

        //输出成GIF文件.
        string strAbsolutePath = (Server.MapPath(".")) + "\\Temp\\test.gif";
        objCSpace.ExportPicture(strAbsolutePath, "GIF", 600, 350);


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

        //显示图片
        Image1.ImageUrl = strRelativePath.ToString();