Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is intended to be a catch-all for legend formatting needs. This comes up often in Stack Overflow questions which can't be easily answered with
valueFormatter. Nowadays I wave my hands and say "write your own legend, either as a plugin or usinghighlightCallbackandunhighlightCallback." This is a simpler option.The
legendFormatteris repeatedly called with adataobject describing the selection or lack of selection. It contains all the information you need to generate a standard legend (e.g. formatted values), but there's nothing preventing you from doing something crazier on your own.For example, here's what a simple
legendFormattermight look like:Here's what the
dataobject looks like when nothing is selected:{ "dygraph": "(dygraph)", "series": [ { "dashHTML": "<div style=\"display: inline-block; position: relative; bottom: .5ex; padding-left: 1em; height: 1px; border-bottom: 2px solid rgb(0,128,0);\"></div>", "label": "Y1", "labelHTML": "Y1", "visible": true, "color": "rgb(0,128,0)" }, { "dashHTML": "<div style=\"display: inline-block; position: relative; bottom: .5ex; padding-left: 1em; height: 1px; border-bottom: 2px solid rgb(0,0,128);\"></div>", "label": "Y2", "labelHTML": "Y2", "visible": true, "color": "rgb(0,0,128)" } ] }The
dashHTMLproperties help you render lines which match each series' line on the chart. WhenstrokePatternis set, they become dotted or dashed lines as needed.Each value has a corresponding
HTMLvariant, which is properly formatted and escaped according to all the relevant options which have been set for the chart.Here's what it looks like when a row is selected:
{ "dygraph": "(dygraph)", "x": 93, "xHTML": 93, "series": [ { "dashHTML": "<div style=\"display: inline-block; position: relative; bottom: .5ex; padding-left: 1em; height: 1px; border-bottom: 2px solid rgb(0,128,0);\"></div>", "label": "Y1", "labelHTML": "Y1", "visible": true, "color": "rgb(0,128,0)", "y": 93, "yHTML": "93" }, { "dashHTML": "<div style=\"display: inline-block; position: relative; bottom: .5ex; padding-left: 1em; height: 1px; border-bottom: 2px solid rgb(0,0,128);\"></div>", "label": "Y2", "labelHTML": "Y2", "visible": true, "color": "rgb(0,0,128)", "y": 26.04, "yHTML": "26.04" } ] }Here's what it looks like when a single series is selected (e.g. with
highlightSeriesOpts):{ "dygraph": "(dygraph)", "x": 94, "xHTML": 94, "series": [ { "dashHTML": "<div style=\"display: inline-block; position: relative; bottom: .5ex; padding-left: 1em; height: 1px; border-bottom: 2px solid rgb(0,128,0);\"></div>", "label": "Y1", "labelHTML": "Y1", "visible": true, "color": "rgb(0,128,0)", "y": 94, "yHTML": "94", "isHighlighted": true }, { "dashHTML": "<div style=\"display: inline-block; position: relative; bottom: .5ex; padding-left: 1em; height: 1px; border-bottom: 2px solid rgb(0,0,128);\"></div>", "label": "Y2", "labelHTML": "Y2", "visible": true, "color": "rgb(0,0,128)", "y": 22.56, "yHTML": "22.56" } ] }(Note the
isHighlightedproperty set onY1.)Fixes #407