【发布时间】:2018-03-02 09:56:41
【问题描述】:
如何在图表控件的 x 轴上显示字符串值?数据点 (x & y) 都是双倍的。我有一个 IEnumerable 包含具有 2 个属性的对象列表。报告的名称和一个整数值,指示它运行了多少次。所以整数在 y 轴上,报告名称在 x 轴上。但我似乎对值类型只有双重选择。所以当我创建我的数据点时,我得到一个错误
DataPoint p1 = new DataPoint();
p1.XValue = log.ReportName; ---> this is invalid
p1.YValues = new Double[] { log.ReportTotal };
如何做到这一点?
我试过了
reportTotal.XValueType = ChartValueType.String;
当我绘制我的数据点时,我已经这样做了
int i = 1;
foreach (var log in this._reportLogs)
{
DataPoint p1 = new DataPoint();
p1.XValue = (double)i;
p1.YValues = new Double[] { log.ReportFrequency };
i++;
reportTotal.Points.Add(p1);
}
但是现在沿 x 轴的所有 im 都是 i 变量的数量,我到底如何才能获取 text 属性的内容?
这就是我的工作方式
Dictionary<string, int> ReportLogs = new Dictionary<string, int>();
foreach (var log in this._reportLogs)
ReportLogs.Add(log.ReportName, log.ReportFrequency);
foreach (KeyValuePair<string, int> log in ReportLogs)
reportTotal.Points.AddXY(log.Key, log.Value);
【问题讨论】:
-
您的问题解决了吗?
-
我沿着 KeyValuePair 路线走下去,效果很好,请参阅我更新的问题
-
好吧,只要你从不需要 x 值就可以了..
标签: c# winforms mschart datapoint