2013-03-17 115 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