Good day, I have a problem with the color scheme of my bar chart. For each time there are 4 values. These values should have 4 different colors. You will find the code and a current picture in the attachment.
I tried several options for the coloring. Nothing works.
For example, if I change the following, the bars will all just be grayed out
backgroundColor: [ "red", "green", "blue", "black", "yellow", ],
Thank you!!!!
public function auswertungBarDiagrammUhrzeiten($daten, $auswertungsKategorien)
{
$html = "";
foreach($daten as $daten_tag_key =>$daten_tag) {
$labelString = "";
$datasetString = "";
$auswertungsKategorien = array_unique($auswertungsKategorien);
sort($auswertungsKategorien);
for ($x = 0; $x < 24; $x++) {
$labelString .= '"' . $x . '",';
}
foreach ($daten_tag as $daten_tag_kategorie_key => $daten_tag_kategorie) {
$dataString = "";
for ($x = 0; $x < 24; $x++) {
$dataString .= '"' . $daten_tag_kategorie[$x . '_A'] . '",';
}
$datasetString .=
'{
label: "'.$daten_tag_kategorie_key.'",
backgroundColor: "red",
data: [' . $dataString . '],
},';
}
$html .= '<canvas id="myBarChartUhrzeiten' . $daten_tag_key . '"></canvas>'
. '<script>
var ctx = document.getElementById("myBarChartUhrzeiten' . $daten_tag_key . '").getContext("2d");
console.log(ctx);
var chart = new Chart(ctx, {
// The type of chart we want to create
type: "bar",
// The data for our dataset
data:
{
labels: [' . $labelString . '],
datasets: [' . $datasetString . ']
},
options:
{
legend:
{
display: false,
},
plugins:
{
datalabels:
{
display: false,
},
}
}
});
</script>';
}
return $html;
}