0

一般来说,我是 JavaScript 和 Web 开发的新手。我有一个 areaspline highchart,作为项目的一部分,我必须能够通过在 y 轴上向上或向下移动曲线上的点来编辑图表。我已经根据保存在服务器上的 csv 文件中的数据创建了图表。我的想法是我可以编辑曲线上的点,然后更新 csv 文件,稍后我可以使用它来创建单独的图形。

我按照这个例子来实现点拖动:http: //jsfiddle.net/highcharts/AyUbx/正在工作。

我遇到的问题是在我编辑图表后更新 csv 文件。我一直在寻找问题的解决方案,但我似乎无法弄清楚。这是 jsfiddle 示例中的函数,其值我需要回发到服务器并写入 csv 文件:

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

如何使用新值 (this.y) 更新服务器上的 csv 文件?

谢谢

4

1 回答 1

2

If you want to post data to your server you can use the jquery post method :

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:

After, you just have to update your file in the updateFile.php page. You can access your data with PHP like this $_POST['ypos'] or $_POST['xpos']

For example if you want to write the new positions in an CSV file :

<?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);
?>
于 2013-03-17T17:05:45.690 回答