asantibanez / livewire-charts

Neat Livewire Charts for your Laravel projects
MIT License
804 stars 120 forks source link

Custom colors in multiline chart. #104

Open dicktornfeldt opened 1 year ago

dicktornfeldt commented 1 year ago

Can we set specific custom color to the different lines in a multiline chart?

Lets say I have 4 different charts on one page.

In two of the graphs there are three different lines (three different brands, X Y and Z). In the third graph, there are only two different lines (two different brands, Y and Z). In the last graph, there are only two different lines (two different brands, X and Z).

I always want brand X, brand Y and brand Z to have their own "brand-color" in all of the charts. Something like:

$chart->addSeriesPoint('Brand X', $date, $value, 'red');
$chart->addSeriesPoint('Brand Y', $date, $value, 'green');
$chart->addSeriesPoint('Brand Z', $date, $value, 'blue');

I know about setColors([...]). But with this I can't connect a color to a certain brand as it's not certain that all different brands will be present in all different charts.

joalea commented 11 months ago

Hi, You can set the color of each line in the multiline chart by adding: ->addColor()

$chart->addSeriesPoint('Brand X', $date, $value)->addColor('#b70000');
$chart->addSeriesPoint('Brand Y', $date, $value)->addColor('#239600');
$chart->addSeriesPoint('Brand Z', $date, $value)->addColor('#0619cc');

The documentation tells you to use addColors but this seems to be wrong.