Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
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 –  PatoCriollo Nov 30 '13 at 17:52
    
@SjoerdC.deVries indeed –  PatoCriollo Mar 18 at 0:58

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
Indeed it does. Thanks @Nasser. :) –  PatoCriollo Nov 30 '13 at 18:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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