per player
This commit is contained in:
parent
f374e81b3e
commit
9853ce05d4
1 changed files with 43 additions and 18 deletions
43
demo.php
43
demo.php
|
|
@ -59,9 +59,24 @@ if ($handle = opendir($directory)) {
|
|||
// $playerData = $dataPointsPerPlayer['Lanta01'];
|
||||
|
||||
// Output the array for debugging purposes
|
||||
echo '<pre>';
|
||||
print_r($dataPointsPerPlayer);
|
||||
echo '</pre>';
|
||||
// At the end of your PHP script, where you previously printed the array
|
||||
// Instead, we will encode the $dataPointsPerPlayer array into JSON
|
||||
$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", {
|
||||
title: {
|
||||
text: "Winrato last month"
|
||||
text: "Win rate by Player"
|
||||
},
|
||||
axisY: {
|
||||
title: "wins"
|
||||
title: "Win Place"
|
||||
},
|
||||
data: [{
|
||||
type: "line",
|
||||
dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
|
||||
}]
|
||||
legend: {
|
||||
cursor: "pointer",
|
||||
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();
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue