Charting data from an Observable
Is it possible to Chart in realtime using an observable?
I have an observable that i can dump in realtime but would be really nice to visualize in a chart.
StockPrice has a timestamp and price (double) but .Chart() does not seem to work with an Observable.
Anybody attempting anything like this or know if its possible?
cheers
Comments
There's no built-in functionality to chart observables in real-time. You could write a custom extension method in My Extensions to do this using the techniques described here:
https://www.linqpad.net/CustomVisualizers.aspx
I have done it with
System.Windows.Forms.DataVisualization.Charting.Chart
and it works just fine to update the series inplace. You must retain the one instance ofChart
that you've dumped though.Try this code:
I don't know much about Reactive Observables, or the DataVisualization charting objects for that matter, but I landed on this thread looking for an answer of how to display LinqPad Chart dumps in real-time (in my case, for some SQL data, updating every second). I eventually found an answer on my own so I'll describe my solution here, even if it's not totally relevant to OP's question, in case anyone else needs help in this more generic scenario.
What I discovered is that if you simply .Dump() from LinqPad's built-in .Chart function, then the output doesn't update until the code finishes... thus, the code below doesn't work very well, because it doesn't show any charts at all until the end of the loop, and then you see each chart individually (1 data point, 2 data points, 3 data points, etc):
The solution I found was to create a DumpContainer, but more importantly, Dump the output of ToBitmap instead of the Chart. This allows the single instance of the DumpContainer to update in real-time (using a DumpContainer without using ToBitmap produces the same problem as in the code above). This code works much better: