Search code examples
javascriptdojodojox.charting

Customised markers/tooltips on a Dojo line chart


I'm using Dojo 1.8 to create a Line chart which I am using to plot time series data. The data consists of samples taken every 5 minutes over a 24 period giving up to 288 (12x24) data points.

In order to have tooltips on the chart, I need to enable markers on the chart (dojo requires this). The problem is that by default, dojo creates one marker for each data point and this results in far too many markers. Ideally, I would show a single marker for the latest data point and maybe markers every hour or two.

It's possible to customise the appearance of a marker but so far I haven't been able to find any way of customising the frequency with which the markers appear. Any suggestions would be very welcome.


Solution

  • Try using the MarkersOnly module:

    require(["dojox/charting/Chart", "dojox/charting/axis2d/Default", "dojox/charting/plot2d/Lines", "dojox/charting/plot2d/MarkersOnly", "dojox/charting/Series", "dojo/ready"],
    function(Chart, Default, Lines, MarkersOnly, Series, ready) {
      ready(function(){
        var chart = new Chart("simplechart");
            chart.addPlot("plot_lines", { type: Lines });
            chart.addPlot("plot_markers", { type: MarkersOnly });
            chart.addAxis("x");
            chart.addAxis("y", {vertical:true});
            chart.addSeries("series_lines", [4, 2, 6, 4, 5, 8, 8, 1, 7, 9]);
            // if you want your markers at data points 6 and 7;
            chart.addSeries("series_markers", [{x:3,y:6}, {x:9,y:7}], { plot: "plot_markers" , stroke: { color: "blue" } });
            chart.render();
      });
    });