I am trying to generate an average line on my line chart.
I tried the following code but it is not working, i would like to plot the average of $tit.
How can i alter my code to achieve this.
<script type="text/javascript">
google.charts.load('current', {
'packages': ['corechart']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['id', 'TIT','Average'],
<?php
$query = "select id,tit1,avg(tit1) as average_tit from engine2";
$res = mysqli_query($conn, $query);
while ($data = mysqli_fetch_array($res)) {
$id = $data["id"];
$tit = $data["tit1"];
$avg = $data["average_tit"];
?>
['<?php echo $id; ?>', <?php echo $tit; ?>, <?php echo $avg; ?>],
<?php
}
?>
]);
var options = {
title: 'T5',
// curveType: 'function',
legend: {
position: 'bottom'
}
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart3'));
chart.draw(data, options);
}
</script>