Chart Disappears

May 28, 2014 at 9:20 PM
Edited May 28, 2014 at 9:21 PM
I used the sample documentation to test this out, it works perfectly fine when the page initially loads, but when I use the click event of a button, it disappears. Is there a work-around for this?

Sample Code Below:

Protected Sub Render_Chart()
Dim connString As String = ConfigurationManager.ConnectionStrings("db").ToString()
    Dim conn As New SqlConnection(connString)

    Dim sql As String = "Select period, rate from sampleTable"

    Dim cmd As New SqlCommand(sql, conn)

    conn.Open()

    Dim rdr As SqlDataReader = cmd.ExecuteReader()

    Dim chartValues(11) As Object

    If rdr.HasRows Then
        While rdr.Read
            chartValues(rdr(0) - 1) = rdr(1)
        End While
   End If
    rdr.Close()

    Dim chart As New DotNet.Highcharts.Highcharts("chart")
    Dim chartType As New DotNet.Highcharts.Options.Chart
    chartType.DefaultSeriesType = DotNet.Highcharts.Enums.ChartTypes.Bar
    chart.InitChart(chartType)
    Dim chartTitle As New DotNet.Highcharts.Options.Title
    chartTitle.Text = "Monthly Rate"
    chartTitle.X = -20
    chart.SetTitle(chartTitle)
    Dim chartSubtitle As New DotNet.Highcharts.Options.Subtitle
    chartSubtitle.Text = "Source: Sample Data"
    chartSubtitle.X = -20
    chart.SetSubtitle(chartSubtitle)
    Dim chartXAxis As New DotNet.Highcharts.Options.XAxis
    Dim months As String() = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
    chartXAxis.Categories = months
    chart.SetXAxis(chartXAxis)

    Dim chartSeries As New DotNet.Highcharts.Options.Series
    chartSeries.Name = "Rate"
    chartSeries.Data = New Data(chartValues)
    chart.SetSeries({chartSeries, chartSeries, chartSeries})


    ltChart1.Text = chart.ToHtmlString

    UpdatePanel1.Update()
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Render_Chart()
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Call Render_Chart()
End Sub
End Class