我可以显示一条消息,如果MS图表控件没有数据? [英] Can I display a message if MS Chart Control has no data?

查看:115
本文介绍了我可以显示一条消息,如果MS图表控件没有数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一个MS图表控件显示一个默认的消息,如果没有数据以图表的方式?

Is there a way to display a "default" message on a MS Chart Control if there is no data to chart?

我有一个表,其中一些控件,允许用户选择不同的日期范围。如果没有数据在该日期范围进行绘制,但目前只是显示没有(或至少它显示图例和背景,但仅此而已。)

I have a chart, with some controls that allow the user to pick various date ranges. If there is no data to be charted in that date range, it currently just displays nothing (or at least it shows the legend, and background, but that's it.)

我希望这是一个消息,说什么的,而不是这期间没有数据。

I want there to be a message saying "no data for this period" or something instead.

谢谢,

推荐答案

在克里斯的反应大厦,这里有一个更完整的例子:

Building on Chris's response, here's a more complete example:

在ASPX code时,OnDataBound处理程序添加到图表标签。这里假设你正在使用一个SqlDataSource数据源。

In the ASPX code, add the OnDataBound handler to the chart tag. This assumes you are using a SqlDataSource for the data source.

<asp:Chart ID="ChartExample" runat="server" 
    DataSourceID="SqlDataSourceExample" 
    OnDataBound="ChartExample_DataBound">

在$ C $的c-背后,处理程序检查该第一系列具有的任何数据,并且如果没有,插入注释红色

In the code-behind, the handler checks if the first series has any data, and if it doesn't, inserts the annotation in red.

protected void ChartExample_DataBound(object sender, EventArgs e)
{
    // If there is no data in the series, show a text annotation
    if(ChartExample.Series[0].Points.Count == 0)
    {
        System.Web.UI.DataVisualization.Charting.TextAnnotation annotation = 
            new System.Web.UI.DataVisualization.Charting.TextAnnotation();
        annotation.Text = "No data for this period";
        annotation.X = 5;
        annotation.Y = 5;
        annotation.Font = new System.Drawing.Font("Arial", 12);
        annotation.ForeColor = System.Drawing.Color.Red;
        ChartExample.Annotations.Add(annotation);
    }
}

这篇关于我可以显示一条消息,如果MS图表控件没有数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆