Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend color behavior #73

Open
fglueck opened this issue Sep 23, 2022 · 1 comment
Open

Legend color behavior #73

fglueck opened this issue Sep 23, 2022 · 1 comment

Comments

@fglueck
Copy link

fglueck commented Sep 23, 2022

In a BarAndLineGraph

     'structure'                 => [ 'key' => 'wk_start',
                                       'value' => ['his', 'jvp', 'cur'], 
                                       'axis_text' => 'wk_start',
                                       'colour' => ['c1', 'c3', 'c2', 'c4'],
    ]
 ...

$colours = ['#e0e0e0', '#aaa', '#286aac']; # '#5f95a5'

with data like:
$data = [
['his': 10, 'jvp':13, 'cur':11, 'wk_start': 'avg', 'c2':'#ff0000'],
['his': 10, 'jvp':13, 'cur':11, 'wk_start': '06.09.'],
['his': 10, 'jvp':13, 'cur':11, 'wk_start': '13.09.'],
.... and a lot of more data
]

All bars get the default color #286aac except the first one ('#ff0000')
The legend will take the color from the first bar => '#ff0000'

If I'm not doomed in your source:
In the Colour Class I found the behavior that the priority for the colour will be like:

  1. from data struct
  2. first element
  3. mod (%) ...

But in this case, we have a legend the priority must be

  1. global (default) if not set ->
  2. data struct ...

I don't found the position in source where the Legend calls the "getColour" Method, but at this position I think it must be handeld by a different Method (not the same for lines or bares) or the Method must be parameterized....

Thanks

@goat1000
Copy link
Owner

For multi-dataset graphs the legend_type option is set to "dataset", which means only the first entry in each dataset is used for the legend.

For more control you can use the legend_text structured data field to set the text for specific entries (instead of using legend_entries) or set the legend_type to "all" and use the legend_entries_callback option to change them after they are generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants