dragon_9000
dragon_9000
2016-04-05 14:13

Google散点图 - {role:'style'} {role:'tooltip'}无法以JSON格式运行

I get google chart data from PHP function in json encoded format which I am passing to "arrayToDataTable" function. I am using $.ajax function. When I pass the following data to the "arrayToDataTable" function

var obj = $.parseJSON('[
    ["goals", "goal", {
        role: 'style'
    }, {
        role: 'tooltip'
    }],
    [54, 0.5, "#0000cf", "54%"],
    [100, 1.5, "#0000cf", "100%"],
    [97, 2.5, "#0000cf", "97%"],
    [87, 2.5, "#0000cf", "87%"]
]')
var data = google.visualization.arrayToDataTable(obj);

It is generating a following error.
SyntaxError: JSON.parse: expected property name or '}' at line 1 column 19 of the JSON data

If data is sent without "style" and "tooltip" columns it is generating a graph as expected.

I am following this post: Google Chart - uncaught error: not an array

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanqizao6492 duanqizao6492 5年前

    In JSON, attribute names must be string.

    Edit: string delimiter should always be " and not '

    So

    {
        role: 'style'
    }
    

    Should be

    {
        "role": "style"
    }
    
    点赞 评论 复制链接分享