1
$\begingroup$

Imagine that we are getting readings from an external device (ie Arduino) at a given interval of time. We'll simulate the reading as follows.

getDataPoint[] := {DateList[], First@RandomVariate[NormalDistribution[0, 1], 1]}
dataList[myList_List, maxPoints_Integer] := 
         Module[{x}, x = Append[myList, getDataPoint[]]; 
         If[Length@x > maxPoints, Take[x, -maxPoints], x]]
data = {}
DateListPlot[ Dynamic[Refresh[data = dataList[data, 15], UpdateInterval -> 1,
TrackedSymbols -> {}]]]

Gives me the following error message

DateListPlot::ntdt: The first argument to DateListPlot should be a list of pairs of dates and real values, a list of real values, or a list of several such lists

If I add the command separately, it does render the chart. Of course, I don't want to display the list data being updated in the screen, just the chart.

Dynamic@DateListPlot[data, Joined -> True]

enter image description here

$\endgroup$
  • $\begingroup$ How can one call data = dataList[data, 15] when data itself does not exist as input? You should post complete self contained working code. $\endgroup$ – Nasser Nov 30 '13 at 17:49
  • $\begingroup$ Forgot to add the line data={}. Now in place $\endgroup$ – Zviovich Nov 30 '13 at 17:52
  • $\begingroup$ @SjoerdC.deVries indeed $\endgroup$ – Zviovich Mar 18 '14 at 0:58
2
$\begingroup$

Will this work for you?

getDataPoint[] := {DateList[],First@RandomVariate[NormalDistribution[0, 1], 1]};

dataList[myList_List, maxPoints_Integer] := Module[{x},
  x = Append[myList, getDataPoint[]];
  If[Length@x > maxPoints, Take[x, -maxPoints], x]];

data = {};

Dynamic@DateListPlot[Refresh[data = dataList[data, 15], UpdateInterval -> 1, 
  TrackedSymbols -> {}], Joined -> True]

enter image description here

$\endgroup$
  • $\begingroup$ Indeed it does. Thanks @Nasser. :) $\endgroup$ – Zviovich Nov 30 '13 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.