首页 > 代码库 > [MSChart]交叉表数据图表绑定

[MSChart]交叉表数据图表绑定

交叉表数据:


显示结果:

Y轴:良率

X轴:日期(动态)

显示项目:检验项目

 private void PassRateBind(Chart ct,string strSql)
        {

            DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.conn, CommandType.Text, strSql).Tables[0];
            ct.DataBindCrossTable(dt.DefaultView, "检验项目", "日期", "良率", "Tooltip =良率");

            ct.Width = 1000;
            ct.Height = 400;
            for (int i = 0; i < ct.Series.Count; i++)
            {
                ct.Series[i].ChartType = SeriesChartType.Line;
            }
     
            ct.ChartAreas["ChartArea1"].ShadowColor = Color.Transparent;
            ct.ChartAreas["ChartArea1"].BackColor = Color.FromArgb(209, 237, 254);         //该处设置为了由天蓝到白色的逐渐变化
            ct.ChartAreas["ChartArea1"].BackGradientStyle = GradientStyle.TopBottom;
            ct.ChartAreas["ChartArea1"].BackSecondaryColor = Color.White;

            //中间X,Y线条的颜色设置
            ct.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
            ct.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
            //X.Y轴数据显示间隔
            ct.ChartAreas["ChartArea1"].AxisX.Interval = 1.0; //X轴数据显示间隔
            ct.ChartAreas["ChartArea1"].AxisX.IntervalType = DateTimeIntervalType.Days;
            ct.ChartAreas["ChartArea1"].AxisX.IntervalOffset = 0.0;
            ct.ChartAreas["ChartArea1"].AxisX.IntervalOffsetType = DateTimeIntervalType.Days;
            ct.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "M-d";

            ct.Palette = ChartColorPalette.Pastel;
            ct.DataBind();
            ct.ChartAreas["ChartArea1"].AxisX.Title = "日期";
            ct.ChartAreas["ChartArea1"].AxisY.Title = "良率";

        }


效果:





[MSChart]交叉表数据图表绑定