Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果没有结果,请在图表区域插入标签_C#_Winforms_Charts - Fatal编程技术网

C# 如果没有结果,请在图表区域插入标签

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

我正在使用C#Windows窗体图表,我想知道当图表中没有任何结果时,是否可以在图表区域显示一个大标签,上面写着“无结果”。

这将添加一个文本注释。每次添加/删除/绑定点时都需要调用它

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如何添加积分!数据绑定?注意允许多次调用的小更新,,