我正在尝试设计一个图表,其中x表示异常消息,y表示发生了多少时间。
我无法在每个小节下显示x值(异常消息),我也尝试标记x并为每个标签设置范围,但是这些小节不是在此标签上生成而是远离它们。
这是我的代码示例
reportChart.Series.Add(exception);
reportChart.Series[exception].SetDefault(true);
reportChart.Series[exception].Enabled = true;
reportChart.Series[exception].Points.AddXY(exception,ExceptionMessages[exception]);
ExceptionMessages[exception]
是一个字典,其中包含当前异常发生的次数的值。
你可以这样做:
private void Form1_Load(object sender, EventArgs e)
{
Dictionary<string, int> ExceptionMessages = new Dictionary<string, int>();
ExceptionMessages.Add("Exception 1", 20);
ExceptionMessages.Add("Exception 2", 50);
ExceptionMessages.Add("Exception 3", 30);
ExceptionMessages.Add("Exception 4", 60);
ExceptionMessages.Add("Exception 5", 10);
foreach (KeyValuePair<string, int> exception in ExceptionMessages)
chart1.Series[0].Points.AddXY(exception.Key, exception.Value);
}
编辑:添加一些逻辑来分配这样的颜色:
foreach (KeyValuePair<string, int> exception in ExceptionMessages)
{
chart1.Series[0].Points.AddXY(exception.Key, exception.Value);
//add business logic for your color here
if (exception.Key == "Exception 4")
chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Color = Color.Red;
}
图表:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句