MSChart控件的一些使用

之前一个项目做数据汇总图形化分析的时候用到了MSChart控件,数据绑定和显示都OK了,就是客户有些小要求:图象显示的时候最好不要有红色(NND,什么人都有啊)。我是用的MSChart的默认设置,最后终于发现第一列显示的都是红色,那就只有改吧,本人偷懒,就只改第一列了(因为其他列显示的颜色还是不错的):

//默认第一列颜色为红色,现改为褐色
cht_Analyse.Plot.SeriesCollection[1].DataPoints[-1].Brush.FillColor.Set( 100,100,100 ) ;
//设置图标说明显示的位置
   this.cht_Analyse.Legend.Location.LocationType = MSChart20Lib.VtChLocationType.VtChLocationTypeBottomLeft ;
//显示图象的坐标值
   forint i = 0 ;i < cht_Analyse.ColumnCount ;i ++ )
   
{
    
this.cht_Analyse.Plot.SeriesCollection.get__Item((short)(i+1)).DataPoints.get

__Item(
-1).DataPointLabel.LocationType = 

MSChart20Lib.VtChLabelLocationType.VtChLabelLocationTypeAbovePoint ;
   }

下面是设置MSChart控件显示类型的一些设置以及初始化设置的部分代码:

配置包含图表类型组合列表框并初始化图表控件

数据绑定部分:

代码
#region 数据获取与图形显示
        
/// <summary>
        
/// 数据获取与图形显示
        
/// </summary>
        private void AnalyseChart()
        {
            sql 
= " select CONVERT(varchar(7), OutDate, 21) as OutDate, "+
                
" sum(allsum_out-allsum_outback) as AllSUm from V_Out_Gather "+
                
" where ( CONVERT(varchar(7), OutDate, 21) between '"+dtpDate1.Text+"' and '"+dtpDate2.Text+"') ";
            sql 
+= " group by CONVERT(varchar(7), OutDate, 21) ";
            DataTable dt 
= so.GetDataset(sql).Tables[0] ;

            cht_Analyse.ColumnCount 
= (short)dt.Rows.Count ;    //
            cht_Analyse.RowCount = 1 ;

            
//显示图例
            cht_Analyse.ShowLegend = true ;
            
forint i = 0 ;i < dt.Rows.Count ;i ++ )
            {
                cht_Analyse.Column 
= (short)(i+1) ;
                cht_Analyse.ColumnLabel 
= dt.Rows[i][0].ToString() ;
            }
            
//设置行标名称    
            cht_Analyse.Row = 1 ;
            cht_Analyse.RowLabel 
= "" ;
            
//绑定数据
            string a = "0" ;
            
forint i = 0 ;i < cht_Analyse.ColumnCount ;i ++ )
            {
                
forint j = 0 ;j < cht_Analyse.RowCount ;j++ )
                {
                    a 
= dt.Rows[i][1].ToString() ;
                    cht_Analyse.DataGrid.SetData( (
short)(j+1),(short)(i+1),double.Parse(a),0 ) ;
                }
            }
            
//设置图标说明显示的位置
            this.cht_Analyse.Legend.Location.LocationType = MSChart20Lib.VtChLocationType.VtChLocationTypeTop;
            
//显示坐标值
            forint i = 0 ;i < cht_Analyse.ColumnCount ;i ++ )
            {
                
this.cht_Analyse.Plot.SeriesCollection.get__Item((short)(i+1)).DataPoints.get__Item(-1).DataPointLabel.LocationType = MSChart20Lib.VtChLabelLocationType.VtChLabelLocationTypeAbovePoint ;
            }

            
if( dt.Rows.Count <= 0)
            {
                MessageBox.Show(
this,"在您选择的日期段内没有数据纪录,无法分析!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                
return ;
            }
        }
        
#endregion

 

下面是根据上面所选样式进行显示的代码:

设置图形控件显示样式
posted on 2006-07-18 17:03  冷月孤峰  阅读(6390)  评论(8)    收藏  举报