10
$\begingroup$

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

$\endgroup$
  • 3
    $\begingroup$ 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"]}] $\endgroup$ – kglr Feb 7 '13 at 1:15
  • $\begingroup$ @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. $\endgroup$ – Mike Honeychurch Feb 7 '13 at 1:29
  • $\begingroup$ I have the same issues with DateListPlot on Windows (both mma versions 8.0.4 and 9.0). $\endgroup$ – kglr Feb 7 '13 at 1:31
  • $\begingroup$ @kguler you mean same issues with slowness or with EvetnHandler? $\endgroup$ – Mike Honeychurch Feb 7 '13 at 3:07
  • $\begingroup$ slowness mostly. $\endgroup$ – kglr Feb 7 '13 at 4:03
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Now that you have explained things in terms simple enough for me to understand, I have deleted my misguided attempt to record an answer. I am pleased, though, that the question is now has an answer. $\endgroup$ – m_goldberg Feb 14 '13 at 3:47
  • $\begingroup$ Mike, why not accept this as a conclusion (as there is no real solution) terminating the issue at hand? $\endgroup$ – István Zachar Feb 21 '13 at 9:00
  • $\begingroup$ ok. I guess it closes it off. $\endgroup$ – Mike Honeychurch Feb 21 '13 at 21:20

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.