I am building an ASP.net application using VB. that uses a chart. I want to add data from the front end and keep that data that is already in the chart. From my research it appears I need the ChartSerializer, but I can not find any code example.
To try to get this to work, I just added a Chart and a button to WebForm1.aspx
In WebForm1.aspx.vb I have coe for a button that adds three records to the graphCode:<asp:Chart ID="Chart1" runat="server"> <Series> <asp:Series Name="Series1"> </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"> </asp:ChartArea> </ChartAreas> </asp:Chart> <asp:Button ID="Button3" runat="server" Text="Button" />
What I want is that every time I click Button3, I want to add three more bars on the graph. What happens now is the chart appears to be recreated, and no matter how many times I hit the button, I only have 3 bars.Code:Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Chart1.Series(0).Points.Add(125) Chart1.Series(0).Points.Add(300) Chart1.Series(0).Points.Add(400) End Sub
What I have tried is to define a public variable to hold the data, add the data to this variable, and then set the Chart.Series(0) equal to that variable. For example
Declare a public class variable in WebForm1.aspx.vb
Then in WebForm1.aspx.vbCode:public s0 as New Series
The data is not persistent. I end up having only one column in my chart.Code:Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click ss0.Points.Add(250) Chart1.Series(0) = ss0 end sub
Any Idea as to how I can get the data to be persistent?




Reply With Quote
