如何在饼图中的图例中设置不同的标签 [英] How to set different Label in Legend in Pie Chart

查看:565
本文介绍了如何在饼图中的图例中设置不同的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在做一个内部有Pie Chart的窗口表单.我需要显示饼图的百分比.

I'm currently doing a window form that have Pie Chart inside.I need to show the percentage of the pie.

但是现在我遇到了一个问题:当我将此#PERCENT{P2}添加到系列中时,Pie Chart将显示如下:

But now I have eencountered a problem : When I add this #PERCENT{P2} to series the Pie Chart will show like this:

但是如果我将其删除,Pie Chart将会显示如下

But if I remove it, the Pie Chart will show like this

是否可以像这样制作Pie Chart?

Is there possible to make the Pie Chart Like this?

我的代码:

DataTable dt = new DataTable();
        dt.Columns.Add("completed", typeof(string));
        dt.Columns.Add("no", typeof(int));
        int noin = allitem - intime;
        dt.Rows.Add("Complete In Time", intime);
        dt.Rows.Add("OverDue", noin);

        chart1.DataSource = dt;

        chart1.DataBind();

推荐答案

是的,可以通过如下方式为每个DataPoints设置LegendText来轻松实现:

Yes, this is easily done by setting the LegendText for each of your DataPoints like this:

foreach (DataPoint dp in yourSeries.Points) dp.LegendText = yourLabel;

如果您的x值包含有意义的数字,则可以使用它们:

If your x-values contain meaningful numbers you can use them:

foreach (DataPoint dp in s.Points) dp.LegendText = dp.XValue + "";

但是,如果您将x值添加为字符串,则它们会丢失,并且您必须为LegendTexts使用其他来源.

But if you added the x-values as strings they are lost and you have to use another source for the LegendTexts.

如果只有固定数量的DataPoints,则可以直接设置LegendTexts:

If you only have a fixed number of DataPoints you can set the LegendTexts directly:

yourSeries.Points[0].LegendText = "hi";
yourSeries.Points[1].LegendText = "ho";
yourSeries.Points[2].LegendText = "hum";

请注意,通常Legend在每个Series中显示一个条目.但是对于Pie图表,它在每个DataPoint中显示一个条目!

Note that usually a Legend shows one entry per Series. But for a Pie chart it shows one entry per DataPoint!

这篇关于如何在饼图中的图例中设置不同的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆