其他分享
首页 > 其他分享> > DevExpress之图表 (ChartControl)

DevExpress之图表 (ChartControl)

作者:互联网

1、自定义图表数据(显示各国人口的折线图)

private void Bind()
{
    List<CountryInfo> countries = new List<CountryInfo> {
        new CountryInfo("中国",14.47f),
        new CountryInfo("印度",14.03f),
        new CountryInfo("美国",3.34f),
        new CountryInfo("印度尼西亚",2.78f),
        new CountryInfo("巴基斯坦",2.28f),
        new CountryInfo("尼日利亚",2.15f),
        new CountryInfo("巴西",2.14f),
        new CountryInfo("孟加拉国",1.67f),
        new CountryInfo("俄罗斯",1.45f),
        new CountryInfo("墨西哥",1.31f),
        new CountryInfo("日本",1.26f),
    };
            

    // 获取已经设置的Series
    //Series s1 = chartControl1.Series[0];
    //s1.Name = "国家人口";
    //s1.DataSource = countries;
    //s1.ArgumentDataMember = "Name";
    //s1.ValueDataMembers[0] = "Population";
    //// 不显示label(图像上是否显示的内容)
    //s1.LabelsVisibility = DevExpress.Utils.DefaultBoolean.False;
    ////定义X轴的数据的类型。质量,数字,时间
    //s1.ArgumentScaleType = ScaleType.Auto;
    ////定义Y轴的数据的类型。质量,数字,时间
    //s1.ValueScaleType = ScaleType.Numerical;
            

    //线条的类型,虚线,实线
    // 自定义的Series
    Series s2 = new Series("图例说明",ViewType.Spline);
    s2.DataSource = countries;
    s2.ArgumentDataMember = "Name";
    s2.ValueDataMembers[0] = "Population";
    LineSeriesView view = s2.View as LineSeriesView;
    //定义线条上点的标识形状 ,只有ViewType是Line时有效
    //view.LineMarkerOptions.Kind = MarkerKind.Circle;
    // 线条的类型,虚线,实线
    //view.LineStyle.DashStyle = DashStyle.DashDotDot;

    chartControl1.Series.Add(s2);

    // 水平调整
    chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right;
    // 垂直调整
    chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
    // 图表样式,是否带有选择框
    chartControl1.Legend.MarkerMode = LegendMarkerMode.MarkerAndCheckBox;
    // 是否显示图例
    chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True;

    XYDiagram xyD =  chartControl1.Diagram as XYDiagram;
    // X坐标轴文字倾斜45度
    xyD.AxisX.Label.Angle = 45;
    // Y坐标轴文字倾斜45度
    //xyD.AxisY.Label.Angle = 45;
    s2.Label.LineVisibility = DevExpress.Utils.DefaultBoolean.True;
    // 是否显示图例说明文本
    chartControl1.Legend.TextVisible = true;
}

2、查询数据库,显示各月工资的柱状图

private void barLargeButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    string sql = "select t.salary_date , t.Real_salary from salary_sheet t where t.salary_type = '工资' order by t.salary_date";

    DataTable dtSalary = SqliteHelper.ExecuteQuery(sql);
    Series s1 = new Series("工资表", ViewType.Bar)
    {
        DataSource = dtSalary,                            
    };

    // 获取柱子的对象
    SideBySideBarSeriesView v1 = s1.View as SideBySideBarSeriesView;
    // 修改柱子的宽度
    v1.BarWidth = 10;
    // 修改柱子的颜色
    v1.Color = Color.FromArgb(227, 108, 9);
    s1.ArgumentScaleType = ScaleType.DateTime;
    s1.ValueScaleType = ScaleType.Numerical;
    s1.ArgumentDataMember = "salary_date";     
    s1.ValueDataMembers[0] = "Real_salary";
    chartControl1.Series.Clear();
    chartControl1.Series.Add(s1);
}

标签:chartControl1,s2,DevExpress,s1,图表,ChartControl,Series,new,CountryInfo
来源: https://www.cnblogs.com/his365/p/16321615.html