设置WinForms图表标签的值

时间:2017-11-19 15:27:53

标签: c# winforms charts

我正在尝试从SQL-Data绘制图表,目前看起来像这样: enter image description here

这是表db.GetTable(cmdGraph)返回: enter image description here

如何设置更改饼图部分的标签以显示字段Count的值,使其看起来像这样?

enter image description here

这是我用来绘制图表的代码:

private void UpdateEvaluation(SqlCommand cmdGraph)
        {
            chPie.DataSource = db.GetTable(cmdGraph);
            chPie.Series["Series1"].XValueMember = "Value";
            chPie.Series["Series1"].YValueMembers = "Count";
            chPie.DataBind();
        }

这就是它被调用的方式:

UpdateEvaluation(new SqlCommand("SELECT Value, Count(*) as Count " +
                        "FROM DV.dbo.tbDefender " +
                        "WHERE Class LIKE 'Operating System' " +
                        "AND Type LIKE 'Caption' " +
                        "GROUP BY Value " +
                        "ORDER BY Count DESC "));

1 个答案:

答案 0 :(得分:0)

我自己发现了:

chPie.Series["Series1"].IsValueShownAsLabel = true;

必须设置值IsValueShownAsLabel。以编程方式或通过Designer(在Chart Series 下的属性中,然后在Label下查找 IsValueShownAsLabel