I want to send a dynamically generated image, created with quickChart, with email in php. For testing i created the chartConfig in the quickChart Sandbox, everything is fine. When i copypaste the config to my php an start it, then i get ChartError: Error: unexpected identifier - 18:26. I don’t get it what the problem is. Here is my code:
$chartConfig = '{
type: "horizontalBar",
data: {
labels: ["Sei perfekt", "Streng dich an", "Sei schnell", "Sei gefaellig", "Sei stark"],
datasets: [
{
backgroundColor: ["#97cc64", "#97cc64", "#97cc64", "#97cc64", "#97cc64"],
data: [26, 30, 25, 26, 25],
barThickness: 30,
},
{
backgroundColor: ["#ffd050", "#ffd050", "#ffd050", "#ffd050", "#ffd050"],
data: [null, 10, null, null, null],
barThickness: 30,
},
{
backgroundColor: ["#fd5a3e", "#fd5a3e", "#fd5a3e", "#fd5a3e", "#fd5a3e"],
data: [null, 5, null, null, null],
barThickness: 30,
},
],
},
options: {
legend: {
position: "bottom",
labels: {
generateLabels: (chart) => [
{
text: "Gesund",
fillStyle: "#97cc64",
},
{
text: "Uebermaessig",
fillStyle: "#ffd050",
},
{
text: "Negativ",
fillStyle: "#fd5a3e",
},
],
},
},
scales: {
xAxes: [
{
stacked: true,
ticks: { min: 0, max: 50, display: true },
gridLines: { display: true },
},
],
yAxes: [{ stacked: true, gridLines: { drawBorder: false } }],
},
},
}';
$chartUrl = 'https://quickchart.io/chart?w=500&h=300&c=' . Urlencode($chartConfig);
$chartUrl is then added to my html. But instead the chart, i get the error image in the email.
Thank you!