2
$\begingroup$

I want to combine IntervalSlider with a small plot,just like the InteractiveTradingChart.

https://reference.wolfram.com/language/ref/InteractiveTradingChart.html

I can only find the closest example here:

Dynamic PlotRange

but the IntervalSlider is still separated with the small plot. I also tried to find the source code of InteractiveTradingChartbut I can't find any.

$\endgroup$
  • $\begingroup$ There is an example under the Applications section in the IntervalSlider doc page, but it is currently broken. $\endgroup$ – Szabolcs Mar 19 at 17:14
2
$\begingroup$

Finally I managed to make it by myself.

DynamicModule[{data, xmin, xmax, ymin, ymax, int, w = 400, h = 30}, 
 data = FinancialData["IBM", "Jan. 1, 2004"];
 {ymin, ymax} = QuantityMagnitude@MinMax[data];
 {xmin, xmax} = {data["FirstTime"], data["LastTime"]};
 Column[{Show[DateListPlot[data, ImageSize -> w, Joined -> True], 
    PlotRange -> {Dynamic[int], {ymin, ymax}}],
   Row[{
     Spacer[10],
     Deploy[DateListPlot[data,
       Prolog -> {Opacity[0.4], EdgeForm[{Thick, GrayLevel[0.4]}], 
         LightBlue, 
         Dynamic[Rectangle @@ Thread[{int, {ymin - 5, ymax + 5}}]]},
       Epilog -> {Inset[
          IntervalSlider[Dynamic[int], {xmin, xmax, 1}, Appearance -> {
             "ThumbAppearance" -> {
               Graphics[{
                 AbsoluteThickness@5, GrayLevel[0.4], 
                 Line@{{0, 0}, {0, 1}}
                 }], None,
               Graphics[{
                 AbsoluteThickness@5, GrayLevel[0.4], 
                 Line@{{0, 0}, {0, 1}}
                 }]
               }, "BarAppearance" -> None
             }, ImageSize -> {400, 50}, Method -> "Stop", 
           MinIntervalSize -> 1], Scaled[{0.5, 0.6}]]},
       Frame -> False, Axes -> {True, False}, 
       PlotRange -> {ymin, ymax}, ImageSize -> {400, 50}, 
       AspectRatio -> 0.08, Joined -> True]
      ]
     }]
   }]]

enter image description here

EDIT: When I apply this to my Manipulate, the coordinates in Dynamic[Rectangle @@ Thread[{int, {ymin - 5, ymax + 5}}]] need to be Scaled, otherwise nothing is displayed, I don't know why.

Also, my timeseries has irregular interval, I need to use AbsoluteTime@DateObject[*data list*] to make it function correctly.

Reference: Slider moving in irregular steps

Make a time IntervalSlider

EDIT2: There is still a problem, which is the top and bottom edge of the rectangle in intervalslider is clipped. You may use

GrayLevel[0.6], Inset@
 Framed[" ", Background -> GrayLevel[0.8], 
  FrameStyle -> AbsoluteThickness[2], 
  FrameMargins -> {{0, 6}, {40, 40}}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ +1, great that you got it working :-) I just came back to take another look, and saw that you managed. $\endgroup$ – Szabolcs Mar 20 at 15:07

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.