C# 如果没有结果,请在图表区域插入标签
我正在使用C#Windows窗体图表,我想知道当图表中没有任何结果时,是否可以在图表区域显示一个大标签,上面写着“无结果”。这将添加一个文本注释。每次添加/删除/绑定点时都需要调用它C# 如果没有结果,请在图表区域插入标签,c#,winforms,charts,C#,Winforms,Charts,我正在使用C#Windows窗体图表,我想知道当图表中没有任何结果时,是否可以在图表区域显示一个大标签,上面写着“无结果”。这将添加一个文本注释。每次添加/删除/绑定点时都需要调用它 void testEmpty(Chart chart) { bool empty = true; foreach (var s in chart.Series) { if (s.Points.Any(x => !x.IsEmpty)) {empty = false; b
void testEmpty(Chart chart)
{
bool empty = true;
foreach (var s in chart.Series)
{
if (s.Points.Any(x => !x.IsEmpty)) {empty = false; break; }
}
if (chart.Annotations.Contains(chart.Annotations["Empty"]))
chart.Annotations.Remove(chart.Annotations["Empty"]);
if (empty)
{
TextAnnotation ta = new TextAnnotation();
ta.Name = "Empty";
ta.X = 30;
ta.Y = 45;
ta.Text = "No Data!";
ta.Font = new Font(Font.FontFamily, 30f);
chart.Annotations.Add(ta);
}
}
你可以玩数字游戏;(50,50)将把左上方放在图表的中心(而不是图表区域)
注意:对于要显示的图表区域
及其轴,仍然需要添加一个虚拟点;如果需要,将其设置为空
chart.Series.First().Points.Add(new DataPoint() { IsEmpty = true });
对于要显示的图表区域,您仍然需要添加一个虚拟点;如果你愿意,就把它弄空。。Fedscribe如何添加积分!数据绑定?注意允许多次调用的小更新,,