Search code examples
c#asp.netvb.netmschart

How to bind data from database into tooltip of a chart point


I want to show some information from a database into tooltip onmouseover. How can I show the information from database into a tooltip of a chart? the data will be based on the database table. I have tried to put the column name but it also produced an error. and I also have look at this site: http://blogs.msdn.com/b/alexgor/archive/2008/11/11/microsoft-chart-control-how-to-using-keywords.aspx there is no format to bind the data from database into tooltip. I just wondering is it possible to do it?

Here is the that I have tried:

<asp:Series ChartType="Line" Name="Series1" Legend="Legend1" LegendText="colummn1" ToolTip="Value of X: #VALY Value of Y #VALY">
            </asp:Series>

it show x and y value...

I also have tried to put the code inside the chart,

Chart1.Series("Series1").ToolTip = "Tooltip: #column1"

it only display 'Tooltip: #column1'... not the value of column1....

Some Code:

    Protected Sub Chart1_Load(sender As Object, e As EventArgs) Handles Chart1.Load
    Dim sqlProducts As String = "Select P, R, L, Column1 from tbl_Name"
    Dim da As New SqlDataAdapter(sqlProducts, conn)
    Dim ds As New DataSet()
    da.Fill(ds, "tbl_name")

    Dim ChartArea1 As ChartArea = New ChartArea()
    Dim Legend1 As Legend = New Legend()
    Dim Series1 As Series = New Series()

    Series1.ChartArea = "ChartArea1"
    Series1.Legend = "Legend1"
    Chart1.TabIndex = 0
    Chart1.Series("Series1").XValueMember = "L"
    Chart1.Series("Series1").YValueMembers = "P"
    Chart1.Series("Series2").YValueMembers = "R"
    Chart1.Series("Series1").ToolTip = "Tooltip: " + "Column1"
    Chart1.ChartAreas(0).AxisY.LabelAutoFitMaxFontSize = "10"
    Chart1.ChartAreas(0).AxisX.LabelAutoFitMaxFontSize = "7"
    Chart1.DataSource = ds.Tables("tbl_name")

Thanks in advance..


Solution

  • You should do it like this

    Chart1.Series("Series1").ToolTip = "Tooltip: " + <Value From DB as string>;
    

    Otherwise, following will show your points (x, y) in when you hover over a point in your chart.

    Chart1.Series("Series1").ToolTip =  "Value of X: #VALY Value of Y #VALY"; 
    

    UPDATE

    Now that you've given the code behind it's easy to answer your question :) Do it like this

    Chart1.Series("Series1").ToolTip = "Tooltip: " + ds.Tables("tbl_name").Rows(1).Column1.ToString()
    

    This will only show the Column1 value of the first row