per player

This commit is contained in:
Lanta 2023-11-08 20:03:52 +01:00
parent f374e81b3e
commit 9853ce05d4

View file

@ -59,9 +59,24 @@ if ($handle = opendir($directory)) {
// $playerData = $dataPointsPerPlayer['Lanta01']; // $playerData = $dataPointsPerPlayer['Lanta01'];
// Output the array for debugging purposes // Output the array for debugging purposes
echo '<pre>'; // At the end of your PHP script, where you previously printed the array
print_r($dataPointsPerPlayer); // Instead, we will encode the $dataPointsPerPlayer array into JSON
echo '</pre>'; $chartData = [];
foreach ($dataPointsPerPlayer as $player => $dataPoints) {
$chartData[] = [
'type' => 'line',
'showInLegend' => true,
'legendText' => $player,
'dataPoints' => $dataPoints
];
}
// Store the JSON encoded data in a PHP variable
$encodedChartData = json_encode($chartData, JSON_NUMERIC_CHECK);
// You can then pass this to your JavaScript code like this
echo "<script>var playerData = $encodedChartData;</script>";
?> ?>
@ -75,20 +90,30 @@ window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", { var chart = new CanvasJS.Chart("chartContainer", {
title: { title: {
text: "Winrato last month" text: "Win rate by Player"
}, },
axisY: { axisY: {
title: "wins" title: "Win Place"
}, },
data: [{ legend: {
type: "line", cursor: "pointer",
dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?> itemclick: function (e) {
}] // Toggle data series visibility on legend item click
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
e.chart.render();
}
},
data: playerData // This will be an array of data series, one per player
}); });
chart.render(); chart.render();
} }
</script> </script>
</head> </head>
<body> <body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div> <div id="chartContainer" style="height: 370px; width: 100%;"></div>