# Issue with DateListPlot and Dynamic List

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]


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

## 1 Answer

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]


-
Indeed it does. Thanks @Nasser. :) –  Zviovich Nov 30 '13 at 18:01