Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding extra information to dygraph legend?

Is there an easy way to be able to add extra data to the dygraph legend?

I obviously want to display the x & y data values, but the underlying data point holds extra information that I want to show to the user.

I can obviously use the callback option to find out what point has been moused over . So is the only option to use the callback and then have my own div which shows this information rather than using the dygraph legend?

like image 758
juckky Avatar asked Sep 12 '26 05:09

juckky


1 Answers

The easiest way to do this is with the legendFormatter option in the upcoming 2.0.0 release:

function legendFormatter(data) {
  if (data.x == null) return '';  // no selection
  return data.xHTML +
      data.series
      .map(v => v.labelHTML + ': ' + v.yHTML)  // modify as needed
      .join(' ');
}

new Dygraph(div, data, { legendFormatter });
like image 143
danvk Avatar answered Sep 14 '26 18:09

danvk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!