10

I have some {date, value} data:

data = Transpose[{AbsoluteTime /@ Thread[{2012, Range[12], 15}], 
   RandomInteger[10, 12]}]

Normally I do initial tests with DateListPlot and then implement with ListPlot or ListLinePlot for efficiency. However I just tried this:

DateListPlot[
 Table[With[{i = i},
   EventHandler[data[[i]], "MouseClicked" :> {Print["hello"]}]], {i, 
   12}]
 ]

and got this error message

DateListPlot::dtvals: Unable to automatically determine horizontal coordinates for the given data and DataRange.

enter image description here

Whereas if I switch to ListPlot or ListLinePlot it works fine:

ListPlot[
 Table[With[{i = i},
   EventHandler[data[[i]], 
    "MouseClicked" :> {Print["hello " <> ToString[i]]}]], {i, 12}]
 ]

enter image description here

Can anyone explain why EventHandler would not work within DateListPlot (hopefully this is not a RTFM question!)?

Problem exists with 8.0.4 and 9.0.1 on Mac 10.6.8

Mike Honeychurch
  • 37,541
  • 3
  • 85
  • 158
  • 3
    Tooltip seems to be only wrapper that works with DateListPlot. EventHandler,Button, PopupWindow ... work with ListPlot but not with DateListPlot. A workaround is to postprocess to replace Tooltip with a wrapper of your choice as in Jens' answer in this Q/A: DateListPlot[Table[With[{i = i}, Tooltip[data[[i]]]], {i, 12}]] /. Tooltip[x_, ___] :> EventHandler[x, "MouseClicked" :> {Print["hello"]}] – kglr Feb 07 '13 at 01:15
  • @kguler I prefer to use ListPlot anyway because DateListPlot is so slow (presumably due to slow date and time functions that are called). So a workaround is unnecessary -- i.e. I'll prototype with ListPlot as well as deploy with it. Was just wondering if what I observed is known and if so whether it is by design or a bug. – Mike Honeychurch Feb 07 '13 at 01:29
  • I have the same issues with DateListPlot on Windows (both mma versions 8.0.4 and 9.0). – kglr Feb 07 '13 at 01:31
  • @kguler you mean same issues with slowness or with EvetnHandler? – Mike Honeychurch Feb 07 '13 at 03:07
  • slowness mostly. – kglr Feb 07 '13 at 04:03
  • @kguler ListLinePlot can be up to an order of magnitude faster, incl. time for absolute time conversion. The catch is you have to make a tick function but small price to pay. For dynamic plots it can be the difference between acceptable and unacceptable updating. Obviously way more overhead in DateListPlot – Mike Honeychurch Feb 07 '13 at 04:11

1 Answers1

3

The objective of the question was to clarify whether EventHandler should work with DateListPlot (work arounds were not sought).

Wolfram tech support confirmed that EventHandler does not work with DateListPlot. This is not a bug it is just that this capability is not available for DateListPlot.

Mike Honeychurch
  • 37,541
  • 3
  • 85
  • 158