-
Dec 21st, 2020, 12:59 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Persistent data in a Chart and Adding points from front end
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
Code:
<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" />
In WebForm1.aspx.vb I have coe for a button that adds three records to the graph
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 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.
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
Code:
public s0 as New Series
Then in WebForm1.aspx.vb
Code:
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
ss0.Points.Add(250)
Chart1.Series(0) = ss0
end sub
The data is not persistent. I end up having only one column in my chart.
Any Idea as to how I can get the data to be persistent?
-
Dec 22nd, 2020, 09:01 PM
#2
Re: Persistent data in a Chart and Adding points from front end
Hi.
Yes asp.net does not maintain values as the pages are stateless.
However you can keep an value in a cookie or in a session or in server memory on in viewstate (worst scenario).
However some controls may do that for you.
Thy reading and then try using "If not page.ispostaback" and the opposite and compare the values
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Dec 22nd, 2020, 09:10 PM
#3
Thread Starter
Fanatic Member
Re: Persistent data in a Chart and Adding points from front end
Thank you for your reply. Other objects were persistent, and the inconsistency with the chart was frustrating.
What I ended up doing is storing all the data into a public list, then then every time I loaded the chart looped through the list and added the data points to the chart. This appears to be working fine for what I want it to do.
-
Dec 22nd, 2020, 09:19 PM
#4
Re: [RESOLVED] Persistent data in a Chart and Adding points from front end
NP.
If there is a javascript made chart then I would rather go with that since asp.net controls are giving hell to the page behind.
If you look at the page source you can see the pages bloating with gibberish data, that is probably the viewstate holding your controls data.
A clean javascript could reduce that dramatically and speed up the pages. But, it's a whole new world .
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|