如何在图表控件的 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 轴得到的都是 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);