chartControl

chartControl_第1张图片

 

右上角和下面的这个2个是chartControl 做的。

chartControl_第2张图片

控件设计 点击 run wizard  ,这里自己慢慢试。

核心代码不多

         gridControl.DataSource = DTReport;
                gridView1.BestFitColumns();
    这是树状图    Series Serices1 = chartControl1.Series[0];
                Serices1.DataSource = DTReport;
                Serices1.ArgumentScaleType = ScaleType.Qualitative;
                Serices1.ArgumentDataMember = "UserName";
                Serices1.ValueScaleType = ScaleType.Numerical;
                Serices1.ValueDataMembers.AddRange(new string[] { "TatalPrice" });
                  Serices1.LabelsVisibility = DefaultBoolean.True;

我的sql:其中用到了 case when 的2中用法 LEFT JOIN 是为了把哪些没有销售业绩的显示出来,比如说,一个新来的销售员,采购单它一张没做,那么就显示为0。
SELECT  UserName ,
        SUM(( CASE CommandTemp1
                WHEN '产品订单' THEN TatalPrice
                ELSE 0
              END )) AS 'ProductOrder' ,
        SUM(( CASE CommandTemp1
                WHEN '模具订单' THEN TatalPrice
                ELSE 0
              END )) AS 'MouldOrder' ,
        SUM(( CASE CommandTemp1
                WHEN '其他订单' THEN TatalPrice
                ELSE 0
              END )) AS 'OtherOrder'
FROM    ( SELECT    UserName ,
                    ( CASE WHEN CommandTemp1 IS NULL THEN '其他订单'
                           ELSE CommandTemp1
                      END ) AS 'CommandTemp1' ,
                    ( CASE WHEN total IS NULL THEN 0
                           ELSE total
                      END ) AS 'TatalPrice'
          FROM      ( SELECT    SU.UserId ,
                                SU.UserName
                      FROM      dbo.SysUser SU
                                INNER JOIN dbo.ItemOrderPlan IOP ON SU.UserId = IOP.salesMan
                    ) SM
                    LEFT JOIN ( SELECT  SO.SalesPeople ,
                                        SO.OrderType ,
                                        SC.CommandTemp1 ,
                                        SUM(So.OrderPrice) AS 'total'
                                FROM    dbo.SalesOrder SO
                                        INNER JOIN dbo.SysCommand SC ON SO.OrderType = SC.CommandNo
                            WHERE OrderDate<'2012-07-01'
                          --   AND MoldNo ='11'
                                GROUP BY SO.SalesPeople ,
                                        SO.OrderType ,
                                        SC.CommandTemp1
                              ) OD ON SM.UserId = OD.SalesPeople
        ) S
GROUP BY UserName


这个结果集我要2次用到,但是第二次用又与第一次用有些差异
所以
    DataTable dt = new DataTable();
                dt.Columns.Add("OrderType");
 
                dt.Columns.Add("TatalPrice"Type.GetType("System.Decimal"));
                DataRow row = dt.NewRow();
                row["OrderType"] = "产品订单";
                row["TatalPrice"] = DTReport.Compute("SUM(ProductOrder)""1=1");
                dt.Rows.Add(row);
 
                DataRow row2 = dt.NewRow();
                row2["OrderType"] = "模具订单";
                row2["TatalPrice"] = DTReport.Compute("SUM(MouldOrder)""1=1");
                dt.Rows.Add(row2);
 
                DataRow row3 = dt.NewRow();
                row3["OrderType"] = "其他";
                row3["TatalPrice"] = DTReport.Compute("SUM(OtherOrder)""1=1");
                dt.Rows.Add(row3);
 
 
                
     这是饼图    Series Serices2 = chartControl2.Series[0];
                Serices2.DataSource = dt;
                Serices2.ArgumentScaleType = ScaleType.Qualitative;
                Serices2.ArgumentDataMember = "OrderType";
                Serices2.ValueScaleType = ScaleType.Numerical;
                Serices2.ValueDataMembers.AddRange(new string[] { "TatalPrice" });
                Serices2.LabelsVisibility = DefaultBoolean.True;


用到自定义table,不在从数据库读取。


你可能感兴趣的:(chart)