c# - 如果没有结果,在图表区域插入标签
问题描述
我正在使用 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 ) 会将 top.left 放在图表的中心(不是图表区域)..
注意:要ChartArea
显示 及其轴,您仍然需要添加一个虚拟点;Empty
如果你愿意就做吧..;
chart.Series.First().Points.Add(new DataPoint() { IsEmpty = true });
推荐阅读
- bash - 谁能帮我理解这个 bash 脚本?
- python - 在python中查找从低到高的状态转换(使用二进制搜索)
- python - 如何用代码块装饰实例并访问/使用实例的变量?
- python - 将文件拆分为列表,然后拆分为单独的部分 - Python
- forms - 使用表单中的条件访问插入
- windows - 从 Windows cmd 提示符读取和编辑文本文件
- python - 如何在 Python 中创建一个上下数字的列表?
- docker - 并行运行 docker 的最佳方法
- parsing - 我的语法不是 LL(1)?哪里不对?
- java - 加载新片段时的 Exoplayer 多个实例