如何在 DataTables 中使用 json 数据作为 Flot

How to use json data for Flot in DataTables

我正在尝试绘制条形图并在下面的 table 中显示该图表的数据。为此,我使用了 flot 和 datatables。我想要做的是在两者中使用 json 输出。

这是我的:

        $.ajax({ 
            type: "POST",
            url: '/index.php',
            dataType: 'json',
            success: function(r) {

                $.plot($("#placeholder"), [r], {
                    series: {
                        bars: {
                            show: true
                        }
                    }
                });


                $('#example').dataTable( {
                    "ajax": r
                } );

            },
            error: function(err) {

                alert("oops");
                return false;

            }

        }); 

图表绘制正常,但数据tables 出现以下错误:

DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

但是,我已经检查了 json,它是有效的并且 flot 使用它很好。 Json 是:

{"data":[[0,1267],[1,1485],[2,1516],[3,1418],[4,1308],[5,1307],[6,1392]]}

这让我得出结论,要么 json 格式对数据 table 不正确,要么 jQuery 错误。谁能指导我?

试试这个:

$('#example').dataTable( {
                    data: r.data
                } );