VB.NET How to reuse/ requery/ reset /clear an existing chart to display new data -


i'm trying reuse chart i'm getting error

a chart element name 'series1' not found in 'seriescollection'.

every time try requery. tried add 3 line of codes before calling function no avail, ideas?

chart1.datasource = nothing chart1.series.clear() chart1.chartareas.clear()

my code:

  private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click    'still getting same error    'chart1.datasource = nothing    'chart1.series.clear()    'chart1.chartareas.clear()    getdata() end sub  private sub getdata()     if not cnninventory.state = connectionstate.open         cnninventory.open()     end if     dim d1 datetime = datetimepicker1.value     dim d2 datetime = datetimepicker2.value     dim searchsql1 new oledb.oledbdataadapter("select * saleshistbl histdate >= #" & string.format("{0:mm/dd/yyyy}", d1) & "# , histdate <= #" & string.format("{0:mm/dd/yyyy}", d2) & "# order histdate ", cnninventory)     dim ds new dataset     searchsql1.fill(ds, "saleshistbl")     chart1.datasource = ds.tables("saleshistbl")     dim series1 series = chart1.series("series1")     series1.name = "sales"     chart1.series(series1.name).xvaluemember = "itemsold"     chart1.series(series1.name).yvaluemembers = "quantity" end sub 

try below, should work well

private sub getdata()     if not cnninventory.state = connectionstate.open         cnninventory.open()     end if     dim d1 datetime = datetimepicker1.value     dim d2 datetime = datetimepicker2.value     dim searchsql1 new oledb.oledbdataadapter("select * saleshistbl histdate >= #" & string.format("{0:mm/dd/yyyy}", d1) & "# , histdate <= #" & string.format("{0:mm/dd/yyyy}", d2) & "# order histdate ", cnninventory)     dim ds new dataset     searchsql1.fill(ds, "saleshistbl")     chart1.datasource = ds.tables("saleshistbl")      chart1.series.clear()     dim series1 new datavisualization.charting.series     series1         .name = "sales"         .charttype = seriescharttype.bar         .xvaluemember = "itemsold"         .yvaluemembers = "quantity"     end     chart1.series.add(series1)     chart1.invalidate()  end sub 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -