如何在 jquery 浮点图中用字符串替换变量

How to replace variable with string in jquery flot graph

我正在使用工作正常的 Flot 折线图:

data1 = [
    [1430369878000, 1690.25],
    [1430369879000, 1696.3],
    [1430369880000, 1659.65]

];


data2 = [
    [1430369878000, 1682.1],
    [1430369879000, 1680.65],
    [1430369880000, 1685.1]

];

然而,当我将 data1 和 data2 替换为:

 dataset = [{
         label: "Team Red",
         data: [
             [1430369878000, 1690.25],
             [1430369879000, 1696.3],
             [1430369880000, 1659.65]
         ],
         color: "#FF0000",
         points: {
             fillColor: "#FF0000",
             show: true
         },
         lines: {
             show: true
         }
     }, {
         label: "Team Blue",
         data: [
             [1430369878000, 1682.1],
             [1430369879000, 1680.65],
             [1430369880000, 1685.1],
             color: "#0062E3",
             points: {
                 fillColor: "#0062E3",
                 show: true
             },
             lines: {
                 show: true
             }
         }
     ];

就是不行,我哪里做错了?

您的第二个 data 值缺少右方括号。试试这个:

dataset = [
    {
        label: "Team Red",
        data: [
            [1430369878000, 1690.25],
            [1430369879000, 1696.3],
            [1430369880000, 1659.65]
        ],
        color: "#FF0000",
        points: {
            fillColor: "#FF0000",
            show: true
        },
        lines: {
            show: true
        }
    }, {
        label: "Team Blue",
        data: [
            [1430369878000, 1682.1],
            [1430369879000, 1680.65],
            [1430369880000, 1685.1]
        ],
        color: "#0062E3",
        points: {
            fillColor: "#0062E3",
            show: true
        },
        lines: {
            show: true
        }
    }
];