I am trying to change the "title text" of a graph that I am using. This graph uses data from PHP and get settings plot in Javascript. But I would like to configure my graph title through a variable from a form of other page. In graph page I can call the selected option from the form of the other page by using $_POST['pol_list"]... So how can I transform "title" in "Selected item from the form"? Thanks!
Here the graph code:
<?php
$dataPoints = array(
array("label"=>"Chrome", "y"=>64.02),
array("label"=>"Firefox", "y"=>12.55),
array("label"=>"IE", "y"=>8.47),
array("label"=>"Safari", "y"=>6.08),
array("label"=>"Edge", "y"=>4.29),
array("label"=>"Others", "y"=>4.59)
)
?>
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title: {
text: "Usage Share of Desktop Browsers"
},
subtitles: [{
text: "November 2017"
}],
data: [{
type: "pie",
yValueFormatString: "#,##0.00\"%\"",
indexLabel: "{label} ({y})",
dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
}]
});
chart.render();
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>
And the form code from another PHP page:
<form action="../view/PlotaGrafico.php" method="post">
<select name="pol_list">
<option value="p1">Item 1</option>
<option value="p2"> Item 2</option>
<option value="p3"> Item 3</option>
<option value="p4"> Item 4</option>
<input type="submit">
</select>
</form>