0

Whenever I change the old value of the highchart with a new value, the highchart still displays the old value.

Each time I need to refresh before new value has been added and displayed to the highchart but I dont know why. Can someone help me how to solve this?

Following is my jQueryportion of code for displaying the chart that uses the Highcharts plugin.

//charts
// JavaScript Document
$(function() {
    var chart;
    $(document).ready(function() {
        $.getJSON("../php/termocouple/line_temp1.php", function(json) {

            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'chart1',
                    type: 'line'

                },
                title: {
                    text: 'Termocouple Graph Result'

                },
                subtitle: {
                    text: ''

                },
                xAxis: {
                    title: {
                        text: 'Sensor'
                    },
                    categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
                },
                yAxis: {
                    title: {
                        text: 'Temperature (°C)'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    formatter: function() {
                        return '<b>' + this.series.name + '</b><br/>' +
                            this.x + ': ' + this.y;
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 120,
                    borderWidth: 0
                },
                series: json
            });
        });
    });
});

and here is the PHP backend code that processes and provides data to Highcharts

<?php
include("../../Connections/koneksi.php");


// Data for Titik1
$sql = "SELECT * FROM temp1 where no ='1'";
$query = mysqli_query($db,$sql);
$rows = array();
$rows['name'] = 'Titik 1';
while($tmp= mysqli_fetch_array($query)) {
    $rows['data'][] = $tmp['sensor1'];
    $rows['data'][] = $tmp['sensor2'];
    $rows['data'][] = $tmp['sensor3'];
    $rows['data'][] = $tmp['sensor4'];
    $rows['data'][] = $tmp['sensor5'];
    $rows['data'][] = $tmp['sensor6'];
    $rows['data'][] = $tmp['sensor7'];
    $rows['data'][] = $tmp['sensor8'];
    $rows['data'][] = $tmp['sensor9'];
    $rows['data'][] = $tmp['sensor10'];
    $rows['data'][] = $tmp['sensor11'];
    $rows['data'][] = $tmp['sensor12'];
}

// Data for Titik2
$sql = "SELECT * FROM temp1 where no ='2'";
$query = mysqli_query($db,$sql);
$rows1 = array();
$rows1['name'] = 'Titik 2';
while($tmp = mysqli_fetch_array($query)) {
    $rows1['data'][] = $tmp['sensor1'];
    $rows1['data'][] = $tmp['sensor2'];
    $rows1['data'][] = $tmp['sensor3'];
    $rows1['data'][] = $tmp['sensor4'];
    $rows1['data'][] = $tmp['sensor5'];
    $rows1['data'][] = $tmp['sensor6'];
    $rows1['data'][] = $tmp['sensor7'];
    $rows1['data'][] = $tmp['sensor8'];
    $rows1['data'][] = $tmp['sensor9'];
    $rows1['data'][] = $tmp['sensor10'];
    $rows1['data'][] = $tmp['sensor11'];
    $rows1['data'][] = $tmp['sensor12'];
}

// Data for Titik3
$sql = "SELECT * FROM temp1 where no ='3'";
$query = mysqli_query($db,$sql);
$rows2 = array();
$rows2['name'] = 'Titik 3';
while($tmp = mysqli_fetch_array($query)) {
    $rows2['data'][] = $tmp['sensor1'];
    $rows2['data'][] = $tmp['sensor2'];
    $rows2['data'][] = $tmp['sensor3'];
    $rows2['data'][] = $tmp['sensor4'];
    $rows2['data'][] = $tmp['sensor5'];
    $rows2['data'][] = $tmp['sensor6'];
    $rows2['data'][] = $tmp['sensor7'];
    $rows2['data'][] = $tmp['sensor8'];
    $rows2['data'][] = $tmp['sensor9'];
    $rows2['data'][] = $tmp['sensor10'];
    $rows2['data'][] = $tmp['sensor11'];
    $rows2['data'][] = $tmp['sensor12'];
}
// Data for Titik4
$sql = "SELECT * FROM temp1 where no ='4'";
$query = mysqli_query($db,$sql);
$rows3 = array();
$rows3['name'] = 'Titik 4';
while($tmp = mysqli_fetch_array($query)) {
    $rows3['data'][] = $tmp['sensor1'];
    $rows3['data'][] = $tmp['sensor2'];
    $rows3['data'][] = $tmp['sensor3'];
    $rows3['data'][] = $tmp['sensor4'];
    $rows3['data'][] = $tmp['sensor5'];
    $rows3['data'][] = $tmp['sensor6'];
    $rows3['data'][] = $tmp['sensor7'];
    $rows3['data'][] = $tmp['sensor8'];
    $rows3['data'][] = $tmp['sensor9'];
    $rows3['data'][] = $tmp['sensor10'];
    $rows3['data'][] = $tmp['sensor11'];
    $rows3['data'][] = $tmp['sensor12'];
}
// Data for Titik 5
$sql = "SELECT * FROM temp1 where no ='5'";
$query = mysqli_query($db,$sql);
$rows4 = array();
$rows4['name'] = 'Titik 5';
while($tmp = mysqli_fetch_array($query)) {
    $rows4['data'][] = $tmp['sensor1'];
    $rows4['data'][] = $tmp['sensor2'];
    $rows4['data'][] = $tmp['sensor3'];
    $rows4['data'][] = $tmp['sensor4'];
    $rows4['data'][] = $tmp['sensor5'];
    $rows4['data'][] = $tmp['sensor6'];
    $rows4['data'][] = $tmp['sensor7'];
    $rows4['data'][] = $tmp['sensor8'];
    $rows4['data'][] = $tmp['sensor9'];
    $rows4['data'][] = $tmp['sensor10'];
    $rows4['data'][] = $tmp['sensor11'];
    $rows4['data'][] = $tmp['sensor12'];
}
// Data for Titik 6
$sql = "SELECT * FROM temp1 where no ='6'";
$query = mysqli_query($db,$sql);
$rows5 = array();
$rows5['name'] = 'Titik 6';
while($tmp = mysqli_fetch_array($query)) {
    $rows5['data'][] = $tmp['sensor1'];
    $rows5['data'][] = $tmp['sensor2'];
    $rows5['data'][] = $tmp['sensor3'];
    $rows5['data'][] = $tmp['sensor4'];
    $rows5['data'][] = $tmp['sensor5'];
    $rows5['data'][] = $tmp['sensor6'];
    $rows5['data'][] = $tmp['sensor7'];
    $rows5['data'][] = $tmp['sensor8'];
    $rows5['data'][] = $tmp['sensor9'];
    $rows5['data'][] = $tmp['sensor10'];
    $rows5['data'][] = $tmp['sensor11'];
    $rows5['data'][] = $tmp['sensor12'];
}
// Data for Titik 7
$sql = "SELECT * FROM temp1 where no ='7'";
$query = mysqli_query($db,$sql);
$rows6 = array();
$rows6['name'] = 'Titik 7';
while($tmp = mysqli_fetch_array($query)) {
    $rows6['data'][] = $tmp['sensor1'];
    $rows6['data'][] = $tmp['sensor2'];
    $rows6['data'][] = $tmp['sensor3'];
    $rows6['data'][] = $tmp['sensor4'];
    $rows6['data'][] = $tmp['sensor5'];
    $rows6['data'][] = $tmp['sensor6'];
    $rows6['data'][] = $tmp['sensor7'];
    $rows6['data'][] = $tmp['sensor8'];
    $rows6['data'][] = $tmp['sensor9'];
    $rows6['data'][] = $tmp['sensor10'];
    $rows6['data'][] = $tmp['sensor11'];
    $rows6['data'][] = $tmp['sensor12'];
}
// Data for Titik 8
$sql = "SELECT * FROM temp1 where no ='8'";
$query = mysqli_query($db,$sql);
$rows7 = array();
$rows7['name'] = 'Titik 8';
while($tmp = mysqli_fetch_array($query)) {
    $rows7['data'][] = $tmp['sensor1'];
    $rows7['data'][] = $tmp['sensor2'];
    $rows7['data'][] = $tmp['sensor3'];
    $rows7['data'][] = $tmp['sensor4'];
    $rows7['data'][] = $tmp['sensor5'];
    $rows7['data'][] = $tmp['sensor6'];
    $rows7['data'][] = $tmp['sensor7'];
    $rows7['data'][] = $tmp['sensor8'];
    $rows7['data'][] = $tmp['sensor9'];
    $rows7['data'][] = $tmp['sensor10'];
    $rows7['data'][] = $tmp['sensor11'];
    $rows7['data'][] = $tmp['sensor12'];
}
// Data for Titik 9
$sql = "SELECT * FROM temp1 where no ='9'";
$query = mysqli_query($db,$sql);
$rows8 = array();
$rows8['name'] = 'Titik 9';
while($tmp = mysqli_fetch_array($query)) {
    $rows8['data'][] = $tmp['sensor1'];
    $rows8['data'][] = $tmp['sensor2'];
    $rows8['data'][] = $tmp['sensor3'];
    $rows8['data'][] = $tmp['sensor4'];
    $rows8['data'][] = $tmp['sensor5'];
    $rows8['data'][] = $tmp['sensor6'];
    $rows8['data'][] = $tmp['sensor7'];
    $rows8['data'][] = $tmp['sensor8'];
    $rows8['data'][] = $tmp['sensor9'];
    $rows8['data'][] = $tmp['sensor10'];
    $rows8['data'][] = $tmp['sensor11'];
    $rows8['data'][] = $tmp['sensor12'];
}
// Data for Titik 10
$sql = "SELECT * FROM temp1 where no ='10'";
$query = mysqli_query($db,$sql);
$rows9 = array();
$rows9['name'] = 'Titik 10';
while($tmp = mysqli_fetch_array($query)) {
    $rows9['data'][] = $tmp['sensor1'];
    $rows9['data'][] = $tmp['sensor2'];
    $rows9['data'][] = $tmp['sensor3'];
    $rows9['data'][] = $tmp['sensor4'];
    $rows9['data'][] = $tmp['sensor5'];
    $rows9['data'][] = $tmp['sensor6'];
    $rows9['data'][] = $tmp['sensor7'];
    $rows9['data'][] = $tmp['sensor8'];
    $rows9['data'][] = $tmp['sensor9'];
    $rows9['data'][] = $tmp['sensor10'];
    $rows9['data'][] = $tmp['sensor11'];
    $rows9['data'][] = $tmp['sensor12'];
}// Data for Titik 11
$sql = "SELECT * FROM temp1 where no ='11'";
$query = mysqli_query($db,$sql);
$rows10 = array();
$rows10['name'] = 'Titik 11';
while($tmp = mysqli_fetch_array($query)) {
    $rows10['data'][] = $tmp['sensor1'];
    $rows10['data'][] = $tmp['sensor2'];
    $rows10['data'][] = $tmp['sensor3'];
    $rows10['data'][] = $tmp['sensor4'];
    $rows10['data'][] = $tmp['sensor5'];
    $rows10['data'][] = $tmp['sensor6'];
    $rows10['data'][] = $tmp['sensor7'];
    $rows10['data'][] = $tmp['sensor8'];
    $rows10['data'][] = $tmp['sensor9'];
    $rows10['data'][] = $tmp['sensor10'];
    $rows10['data'][] = $tmp['sensor11'];
    $rows10['data'][] = $tmp['sensor12'];
}


$result = array();
array_push($result,$rows);
array_push($result,$rows1);
array_push($result,$rows2);
array_push($result,$rows3);
array_push($result,$rows4);
array_push($result,$rows5);
array_push($result,$rows6);
array_push($result,$rows7);
array_push($result,$rows8);
array_push($result,$rows9);
array_push($result,$rows10);


print json_encode($result, JSON_NUMERIC_CHECK);

mysqli_close($db);
?>
Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
Minervaz Mine
  • 273
  • 1
  • 3
  • 17
  • You originally typed "_i have a problem while selecting highchart graph value_" - does that mean showing/displaying the value, like in the tooltip? or do you mean that the version of highcharts is changing? If so, which version are you switching from and which version are you switching to? – Sᴀᴍ Onᴇᴌᴀ Jul 27 '17 at 06:05
  • highchart is initialized only once with data in you code.Either make setInterval or any manual action to make xhr request for new data and reinitialize highchart – Deep 3015 Jul 27 '17 at 06:06
  • @SamOnela my problem like this. from that code i add in my question. it will show my data into highchart. and the problem is. i select other data with where clause and want to make it display in that highchart. the data is same from one table but it has different value. after i selecting that. the data that i select with where clause not showing at the highchart. i try to use page reload but still same – Minervaz Mine Jul 27 '17 at 07:46
  • @Deep3015 nah i try to make new function for do new action for request new data and re-initialize the highchart. but still the chart not refresh the data – Minervaz Mine Jul 27 '17 at 07:52
  • try this https://stackoverflow.com/q/45342699/3898339 may help – Deep 3015 Jul 27 '17 at 08:16
  • "_i try to make new function for do new action for request new data and re-intialize the highchart._" Can you please edit your question to contain that code? – Sᴀᴍ Onᴇᴌᴀ Jul 27 '17 at 14:34
  • Check if you don't insert the same data into chart, by any chance. Also, link provided by @Deep3015 should be helpful. – pawel_d Jul 27 '17 at 15:47
  • @d_paul bro.. I have a problem again. – Minervaz Mine Jul 31 '17 at 03:20
  • From my php function. When i add `$tanggal1=$_POST['tanggal1']` and i give where clause on my sql function `sql="SELECT * FROM temp1 where no ='3' and tanggal='$tanggal1'"; `. I try call the data with the script above and the data not displayed. But when i remove the `$tanggal1=$_POST['tanggal1']` the data can be displayed – Minervaz Mine Jul 31 '17 at 03:27
  • Why like the php function has behavior like that? – Minervaz Mine Jul 31 '17 at 03:27

1 Answers1

0

I got the answer for this now. i just must make two function for calling the graph. 1st function with php that just calling the display function without where clause 2nd function with php that just calling the display function with where clause

the i just call redraw on the script for showing the highchart.

Minervaz Mine
  • 273
  • 1
  • 3
  • 17