C# 中使用MSChart组件

    这两天在研究怎样在 C# 中使用MSChart组件来绘制柱状、饼状图形,由于以前没有接触过MSChart组件,关于这方面的资料也没有;于是就到网上狂搜一把,找到了一些相关的资料,但资料都写的不完整; 现在将自己摸索的心得整理一下:

 

1、将MSChart control的引用添加到工具栏。

 

   选择“工具->选择工具箱项”, 然后切换到“COM 组件”页,选择“Microsoft Chart Control 6.0 (OLEBD)”,点击确定后就可以成功加载控件了。

 

 

2添加引用,using MSChart20Lib;

 

3、定义图表样式

           

//图表标题         

MSChartBar.TitleText = "年度统计图表";

           

//页底说明          

MSChartBar.Footnote.Text = "说明:年度柱状统计图表";

           

//设置图例          

MSChartBar.ShowLegend = true;
           

MSChartBar.Legend.Location.LocationType = VtChLocationType.VtChLocationTypeRight;

          
           

//设置PlotShadow          

MSChartBar.Plot.Backdrop.Shadow.Style = VtShadowStyle.VtShadowStyleDrop;
          
           

//设置Shadow的大小          

MSChartBar.Plot.Backdrop.Shadow.Offset.Set(60, 60);
          
           

//设置Plot的边框          

MSChartBar.Plot.Backdrop.Frame.Style = VtFrameStyle.VtFrameStyleSingleLine;
        
          

//关闭选择          

MSChartBar.AllowSelections = false;

 

4、显示数据            

MSChartBar.RowCount = 12;            

MSChartBar.ColumnLabel = "温度";

                    

// Y轴名称             

MSChartBar.Plot.get_Axis(VtChAxisId.VtChAxisIdY, 0).AxisTitle.Text = "温度"; 
                       

// X轴名称     

MSChartBar.Plot.get_Axis(VtChAxisId.VtChAxisIdX, 0).AxisTitle.Text = "月份";
             

for(int row = 1; row <= 12; ++row)          

{               

    MSChartBar.Row = (short)row;                 

    MSChartBar.RowLabel = Convert.ToString(row);                 

    MSChartBar.DataGrid.SetData((short)row, 1, 12*row, 0);                             

 }

            

MSChartBar.Refresh();

 

    基本可以满足一般需求了,需要完善的有-显示百分比数值。

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值