2013-03-17 32 views
0

我是JavaScript和一般網頁開發的新手。我有一個areaspline高圖,作爲項目的一部分,我必須能夠通過在y軸上向上或向下移動曲線上的點來編輯圖表。我從保存在服務器上的csv文件中的數據創建了圖表。我的想法是,我可以編輯曲線上的點,然後更新csvfile,稍後可以使用它來創建單獨的圖。編輯圖表後在HighChart上更新系列數組

我跟着這個例子來實現點拖動:http://jsfiddle.net/highcharts/AyUbx/這是工作。

我遇到的問題是在我編輯圖表後更新了csv文件。我一直在尋找解決問題的辦法,但我似乎無法弄清楚。 這裏與我需要回發到服務器並寫入csv文件的值的jsfiddle比如函數:

drop: function() { 
    $('#drop').html(
    'In <b>' + this.series.name + '</b>, <b>' + 
    this.category + '</b> was set to <b>' + 
    Highcharts.numberFormat(this.y, 2) + '</b>' 
    ); 
    }` 

如何更新爲新值在服務器上的CSV文件(本.Y)?

感謝

回答

2

如果你想將數據發佈到你的服務器,你可以使用jQuery的崗位方法:

drop: function() { 
    $('#drop').html(
    'In <b>' + this.series.name + '</b>, <b>' + 
    this.category + '</b> was set to <b>' + 
    Highcharts.numberFormat(this.y, 2) + '</b>' 
    ); 
    $.post("updateFile.php", { ypos: this.y , xpos: this.x}); // like this 
}` 

UPDATE:

之後,你只需要更新文件在updateFile.php頁面中。您可以使用PHP訪問您的數據是這樣$_POST['ypos']$_POST['xpos']

例如,如果你想要寫在CSV文件中的新位置:

<?php 
// 1 : open the file 
$myfile = fopen('myfile.csv', 'a+'); 

// 2 : write at the end of the file 
fputs($myfile, $_POST['ypos'] . "; " . $_POST['xpos'] . "\n"); 

// 3 : when we have done, we close the file 
fclose($myfile); 
?> 
+0

的感謝!從那裏我只寫了一個更新csv文件的php腳本?如何指定csv文件中的哪個值需要更新? – bergundy195 2013-03-17 17:13:32

+2

@ bergundy195您可以在POST請求中傳遞修改點的x座標,然後服務器端進程可以確定需要更新哪個點:$ .post(「updateFile.php」,{xpos:this。 x,ypos:this.y});'。參考:http://api.highcharts.com/highcharts#Point – tcovo 2013-03-17 17:47:26

+0

@ bergundy195,如果我的回答滿足你,你會接受嗎,還是你需要更多的信息? – Pith 2013-03-18 12:30:58