Search code examples
dygraphs

Add additional data to dygraphs point


Is it possible in dygraph to add additional data to a point?

For example:

X, Y, myId
[
[1, 2, 'some id value'],
[1, 2, 'some other id value'],
[1, 2, 'some value']
]

And then be able to get myId again in drawPointCallback for instance, so I can decide how to draw a point based on the type of value.

Or: when the user clicks on a point, some click callback fires and I can obtain this id to do further actions.


Solution

  • If you'd like to store a number, you could put it in a hidden series. Or you could use an auxiliary array with the same number of entries as your data has rows, e.g.

    var data = [[1, 2], [1, 2], [1, 2]];
    var auxiliary = ['some id value', 'some other id value', 'some value'];
    new Dygraph(div, data, {
      pointClickCallback: function(e, pt) {
        console.log(auxiliary[pt.idx]);
      }
    });