【问题标题】:Update Series Array on HighChart after editing the chart编辑图表后更新 HighChart 上的系列数组
【发布时间】:2013-03-17 16:51:33
【问题描述】:

总的来说,我是 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 文件?

谢谢

【问题讨论】:

    标签: javascript jquery ajax csv highcharts


    【解决方案1】:

    如果您想将数据发布到您的服务器,您可以使用 jquery post 方法:

    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
    }`
    

    更新:

    之后,您只需在 updateFile.php 页面中更新您的文件。你可以像$_POST['ypos']$_POST['xpos']这样使用PHP访问你的数据

    例如,如果您想在 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);
    ?>
    

    【讨论】:

    • 谢谢!从那里我只是编写一个更新 csv 文件的 php 脚本?如何指定 csv 文件中的哪个值需要更新?
    • @bergundy195 您可以在 POST 请求中传递修改点的 x 坐标,然后服务器端进程可以确定需要更新的点:$.post("updateFile.php", { xpos: this.x, ypos: this.y } );。参考:api.highcharts.com/highcharts#Point
    • @bergundy195,如果我的回答让你满意,你会接受,还是需要更多信息?
    • 是的,我在那里尝试过,它似乎工作正常。谢谢
    猜你喜欢
    • 1970-01-01
    • 2023-01-31
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多