Fusher wrote:Of course, if your data.txt coantains only 100 values, so only 100 values will be shown. If your data.txt will get more values you need to call another $.get() to update your data.
Hi Fusher
Thank you for your reply to my post.
I have an external txt file (named data.txt) containing only the real time data. The file looks like below:
0v;
1v;
2v;
3v;
4v;
….
99v;
I am still struggling with the code. It only displays the first 100 points and stop with Highcharts. It seems that the real-time data is still not picked up by Highcharts. I am just guessing that because my TXT file can not be refreshed itself… needs to use the XMLHttpRequest function to request data from data.txt.
After reading the case study on highchart website, I think I need to use an Ajax framework to load the data each half second from the server but my input data was not formatted as JSON.
I tried to write code and use the Highcharts addPoint method several times, but I am too new with Ajax and can not handle it. I would appreciate it if you could give me a hand.
I modified an Ajax demo before knowing Highcharts, all variables are refreshed every half second successfully on the index.htm and the webpage don’t need to refresh. The javascript code is as follows. I think there should be a way to modify the code as below and add Highcharts method. I am not able to deal with it. Please please help me…
var response = 0;
var responsebutton = 1;
var ansvers = 0;
var i
var horz
function get_data_loop()
{
if(!ansvers){
get_data();
ansvers = 1;
}
setTimeout("get_data_loop()",500);
}
function open_ActiveXobject()
{
var http_request;
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {}
}
}
if(!http_request){
alert('Cannot create XMLHTTP');
return 0;
}
return http_request;
}
function server_response(http_request)
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
response=0;
}else
{
response = 0;
}
}
}
function infinite_loop()
{
if(!response)
make_request("data.txt");
}
function get_data()
{
var http_request = open_ActiveXobject();
if(!http_request) return 0;
http_request.onreadystatechange = function() {server_ansvers(http_request);};
http_request.open('GET', 'data.txt?', true );
http_request.send(null);
}
function server_ansvers(http_request)
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
process_data(http_request.responseText);
ansvers=0;
}else
{
ansvers = 0;
}
}
}
horz = 0
window.onload=get_data_loop;
function process_data(data)
{
var parsed = data.split( "\n" );
var a1 = parseInt(parsed[0],10);
var a2 = parseInt(parsed[1],10);
var a3 = parseInt(parsed[2],10);
var a4 = parseInt(parsed[3],10);
var a5 = parseInt(parsed[4],10);
………
var a97 = (parseInt(parsed[96],10));
var a98 = (parseInt(parsed[97],10));
var a99 = (parseInt(parsed[98],10));
var a100 = (parseInt(parsed[99],10));
document.getElementById("display_a1").value = a1;
document.getElementById("display_a2").value = a2;
document.getElementById("display_a3").value = a3;
document.getElementById("display_a4").value = a4;
document.getElementById("display_a5").value = a5;
……..
document.getElementById("display_a97").value = a97;
document.getElementById("display_a98").value = a98;
document.getElementById("display_a99").value = a99;
document.getElementById("display_a100").value = a100;
}
I am looking forward to hearing from you soon. Many thanks
All the best
Selina