DevExpress chart 制作树状图

此篇中先展示效果,随后再解释代码

DevExpress chart 制作树状图_第1张图片
图片.png

如图所示,有一个柱状图有一条折线图
其中柱状图显示的是我从后台获取的数据
折线图显示的是第二个Y轴所表示的完成率
想要让前台显示出柱状图(此处省略建前台画面的介绍)
在画面中先拖入一个chartcontrol,点右上角的1>箭头,会出现series
点击add后会让你选择你要添加的chart的类别
选择bar close

前台代码如下

private void FormOIMMHP01_Load(object sender, EventArgs e)
{
Series1();
//Series2();
}
private void Series1()
{
//string REC_CREATE_TIME = DateTime.Now.AddMonths(-1).AddDays(1 - DateTime.Now.Day).ToString("yyyyMMdd");
//string REC_CREATE_TIME2 = DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyyMMdd");
DataTable data = new DataTable();
DataTable datasum = new DataTable();
string WORKDATE = DateTime.Now.ToString("yyyyMMdd");
EI.EIInfo inBlock = new EI.EIInfo();
EI.EIInfo outBlock;
inBlock.Tables[0].Columns.Add("WORKDATE", typeof(String));
//inBlock.Tables[0].Columns.Add("kind", typeof(int));
//inBlock.Tables[0].Rows.Add(REC_CREATE_TIME == null ? " " : REC_CREATE_TIME, REC_CREATE_TIME2 == null ? "99999999" : REC_CREATE_TIME2, 0);
inBlock.Tables[0].Rows.Add(WORKDATE == null ? " " : WORKDATE);
outBlock = EI.EITuxedo.CallService("oimmhp01f2_inq", inBlock);
chartControl1.Series.Clear();
data = outBlock.Tables[0];
try
{
Series series1 = new Series("日产量", ViewType.Bar);
Series series2 = new Series("月累计", ViewType.Bar);
Series series3 = new Series("计划量", ViewType.Bar);

            chartControl1.Series.Add(series1);
            series1.DataSource = data;
            series1.ArgumentScaleType = ScaleType.Auto;
            series1.ArgumentDataMember = "PROD_CODE_CNAME";
            series1.ValueScaleType = ScaleType.Numerical;
            series1.ValueDataMembers.AddRange(new string[] { "PROD_CODE_VALUE_D" });
            ((BarSeriesView)series1.View).BarWidth = 0.5;

            chartControl1.Series.Add(series2);
            series2.DataSource = data;
            series2.ArgumentScaleType = ScaleType.Auto;
            series2.ArgumentDataMember = "PROD_CODE_CNAME";
            series2.ValueScaleType = ScaleType.Numerical;
            series2.ValueDataMembers.AddRange(new string[] { "PROD_CODE_VALUE_M" });
            ((BarSeriesView)series2.View).BarWidth = 0.5;

            chartControl1.Series.Add(series3);
            series3.DataSource = data;
            series3.ArgumentScaleType = ScaleType.Auto;
            series3.ArgumentDataMember = "PROD_CODE_CNAME";
            series3.ValueScaleType = ScaleType.Numerical;
            series3.ValueDataMembers.AddRange(new string[] { "PROD_CODE_VALUE_P" });
            ((BarSeriesView)series3.View).BarWidth = 0.5;

            datasum = outBlock.Tables[0];
            Series series4 = new Series("完成率", ViewType.Line);
            series4.DataSource = datasum;
            series4.ArgumentScaleType = ScaleType.Qualitative;
            series4.ArgumentDataMember = "PROD_CODE_CNAME";
            series4.ValueScaleType = ScaleType.Numerical;
            series4.ValueDataMembers.AddRange(new string[] { "PROD_CODE_VALUE_R" });
            chartControl1.Series.Add(series4);

            SecondaryAxisY myAxis = new SecondaryAxisY(series4.Name);
            myAxis.Label.NumericOptions.Format = NumericFormat.Percent;//格式化,为了显示百分号
            ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add(myAxis);
            ((LineSeriesView)series4.View).AxisY = myAxis;
        }
        catch (Exception)
        {
            throw;
        }
    }

有哪里不懂的朋友可以私信我,我还有饼状图,折线图,3D饼状图,3D柱状图,仪表盘等等要做

你可能感兴趣的:(DevExpress chart 制作树状图)