javascript - 带有外部 ajax 数据的图表 PHP

标签 javascript php jquery charts

我的网站上有一个图表js! 我在从外部 PHP 页面获取数据时遇到问题。有人可以帮助我吗?

var result = [];

        $.ajax({
                url: 'x.php',
                dataType: 'text',
                async: false,
                success:  function(data) {
                        items = data
                }
        });

     result = items


        var dataProcessosAtivos = [
                result
        ];

原变量如下:

var dataProcessosAtivos = [
        [0, 4],
        [1, 8],
        [2, 0],
        [3, 0],
        [4, 0],
        [5, 0],
        [6, 0],
        [7, 0],
        [8, 0],
        [9, 0],
        [10, 0],
        [11, 0]
];

这是一个 x.php:

    $json = "[0,87],[1, 14],[2, 16],[3, 0],[4, 0],[5, 0],[6, 0],[7, 0],[8, 0],[9, 0],[10, 0],[11, 0]";

    echo json_encode($json);

最佳答案

将 php 文件内容更改为以下内容。如果它是 DOM 中的现有图表,请确保图表在设置结果后重新绘制。

// This tells the bellow content is JSON
header ('content-type: application/json');

// Actual PHP array
$json = [[0,87],[1, 14],[5, 0],[6, 0],[7, 0],[8, 0],[9, 0],[10, 0],[11, 0]];

// Printing JSON string
echo json_encode($json);

关于javascript - 带有外部 ajax 数据的图表 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37152166/

相关文章:

javascript - 从Elasticsearch下载300,000+行作为.csv文件

javascript - 将 JavaScript 的映射与对象的方法一起使用

javascript - JSONForms Vue 基本字符串自定义渲染器

php - WordPress 按 wp_postmeta 中的查询排序

javascript - 防止 jQuery 函数重复效果两次?

javascript - 使用 jquery 将 anchor 添加到链接

javascript - 为什么在 Javascript 中使用正则表达式来验证经纬度?

php - 从一个单词之后但另一个单词之前的字符串中获取特定单词?

php - call_user_func_array 与 $controller->$method($params)?

jquery - 如何在 AngularJS 中监听 jQuery 事件