Google柱形图 - 列值与轴不匹配

时间:2013-12-02 14:58:58

标签: javascript google-visualization

我的柱形图如下:

enter image description here

我添加了数据的值,正如您所看到的那样,相对于Y轴的列没有意义 - 为什么会这样?

图表选项:

var options = {
    title: 'Task Estimates',
    backgroundColor: { fill: 'transparent' },
    chartArea: { width: '50%' },
    height: '400px',
    hAxis: { direction: -1, slantedText: true, slantedTextAngle: 45, title: 'Tasks' },
};

var url = "http://theurl";

$.getJSON(url, function (jsonChartData) {

    var data = new google.visualization.DataTable(jsonChartData);

    var chart = new google.visualization.ColumnChart(chartHtmlElement);
    chart.draw(data, options);

});

json是:

{
    "cols":[
        { "id":"A", "label":"Task", "type":"string", "role":null },
        { "id":"B", "label":"Days Estimated", "type":"number", "role":null },
        { "id":"C", "label":"Days Actual", "type":"number", "role":null }
    ],
    "rows":[
        { "c":[ { "v":"Task 3" }, { "v":"7" }, { "v":"4" } ] },
        { "c":[ { "v":"Task 1" }, { "v":"10" }, { "v":"24" } ] },
        { "c":[ { "v":"Task 2" }, { "v":"100" }, { "v":"0" } ] }
    ],
    "p":null
}

我做错了什么?是否还需要指定其他方法才能使轴正常工作?

的jsfiddle

http://jsfiddle.net/6K3Wc/1/

1 个答案:

答案 0 :(得分:2)

您输入的数字为字符串,应以数字形式输入:

{
    "cols":[
        {
            "id":"A",
            "label":"Task",
            "type":"string",
            "role":null
        },
        {
            "id":"B",
            "label":"Days Estimated",
            "type":"number",
            "role":null
        },
        {
            "id":"C",
            "label":"Days Actual",
            "type":"number",
            "role":null
        }
    ],
    "rows":[
        {
            "c":[
                {
                    "v":"Task 3"
                },
                {
                    "v":7
                },
                {
                    "v":4
                }
            ]
        },
        {
            "c":[
                {
                    "v":"Task 1"
                },
                {
                    "v":10
                },
                {
                    "v":24
                }
            ]
        },
        {
            "c":[
                {
                    "v":"Task 2"
                },
                {
                    "v":100
                },
                {
                    "v":0
                }
            ]
        }
    ],
    "p":null
}