per player
This commit is contained in:
parent
7cfb3a8e40
commit
e57291bac6
1 changed files with 43 additions and 18 deletions
49
demo.php
49
demo.php
|
|
@ -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>";
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
@ -73,22 +88,32 @@ echo '</pre>';
|
||||||
<script>
|
<script>
|
||||||
window.onload = function () {
|
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) {
|
||||||
chart.render();
|
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>
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
|
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue