ASP.NET 4.0 Chart - How do I display an explanatory message in the chart area when a data binding query returns no results?

I have a .Net 4 Chart Control associated with a saved proc. For some queries selected by the client, the chart will be empty. I would like to display the message “No data” in the empty chart area so that the clients understand why the chart is empty. I could not find information on how to do this.

+3
source share
1 answer

I had the same problem. I solved this by doing this in my code:

If MySQLReader.Read Then
            Chart1.DataSource = MySQLReader
            Chart1.Series("Series1").XValueMember = "XValue"
            Chart1.Series("Series1").YValueMembers = "YValue"
            Chart1.Height = 500
            Chart1.Width = 750
            Chart1.DataBind()
            LBLError.Text = ""
        Else
            Chart1.Visible = False
            LBLError.Text = "Your search did not match any records in the database"
            MySQLReader.Close()
            MyConn.Close()
        End If

Hope this helps.

0
source

Source: https://habr.com/ru/post/1764968/


All Articles