dygraphs icon indicating copy to clipboard operation
dygraphs copied to clipboard

Need to show multiple colours for differentiating between data on the same line graph.

Open SaiVikas0801 opened this issue 4 years ago • 3 comments

Hi,

I have requirement to show multiple colours on the same line graph. This is basically to differentiate the various stages of data.

I haven't found any such option available in dygraph. Can someone help on how to achieve this.

SaiVikas0801 avatar May 13 '20 19:05 SaiVikas0801

Solution 1: Split your data in different time series for each color and assign the colors as usual. This may blow up your underlying dataset, but is quite easy to implement. You may have to add a value/or LegendFormatter to display values properly.

Solution 2: If your drawing only points you can use the drawPointCallbacks. Refer to the docs or Stack Overflow on how to achieve this.

Solution 3: Implement a custom plotter. http://blog.dygraphs.com/2012/08/introducing-custom-plotters.html

Solution 3 is the cleanest way to achieve your goal.

andnorxor avatar May 15 '20 13:05 andnorxor

Thanks for the response andnorxor.

If possible can you share some more light on solution 1. Any example or sample link would be really useful. Thanks

SaiVikas0801 avatar May 15 '20 13:05 SaiVikas0801

Sry, I have no minimal example to share. I did this already, but there's too much code overhead (additional functionalities) to share it as an example.

Maybe this will help you to get a better understanding.

The following represents values over time:

Time: 0 1 2 3 4 5
Serie: 5 2 3 1 2 8

To get different colors you just have to split this series and fill the missing values with nulls.

Let's say we want show the values from time 1 to 2 and from 4 to 5 in another color. Then you have to transform your underlying data s follows:

Time:     0      | 1       |  2          | 3         |  4        | 5
SeriesA:  5      | 2       |   null      | 1         |  2        | null
SeriesB:  null   | 2       |  3          |  null     |  2        |  8

Then you have to format the legend, otherwise a value for each series shows up.

andnorxor avatar May 15 '20 14:05 andnorxor