Google饼图无法正确显示切片

时间:2013-12-06 11:01:25

标签: javascript google-api google-visualization pie-chart

正如您在下图中所看到的,我的网页上有很多饼图,并且它们没有完全填满容器(通常只有一半填充或少量):

Google Visualization API - Pie Chart Visualization Problem

这里有一些代码:

        var data1 = google.visualization.arrayToDataTable([
            ['Tipo', 'Valore'],
            ['Recapitate', sent],
            ['Ritornate/Bloccate', errors]
        ]);

        options1 = {
            width: 250,
            height: 250,
            pieHole: 0.5,
            colors: ['#06dd00','#e12a00'],
            legend: {position: 'none'},
            pieSliceText: 'none',
            tooltip: {textStyle: {color: '#333', fontName: 'Arial', fontSize: 16}},
            chartArea:{left: 0,top: 0,width: "100%",height: "100%"},
            enableInteractivity: false/*,
            animation: { duration: 1000, easing: 'out' }*/
        };

        chart1 = new google.visualization.PieChart(document.getElementById('grafico-inviate'));
        chart1.draw(data1, options1);

        var data2 = google.visualization.arrayToDataTable([
            ['Tipo', 'Valore'],
            ['Aperte', unique_opened],
            ['Non aperte', combined1]
        ]);

        options2 = {
            width: 250,
            height: 250,
            pieHole: 0.5,
            colors: ['#3e9ca8','#ff5932'],
            legend: {position: 'none'},
            pieSliceText: 'none',
            tooltip: {textStyle: {color: '#333', fontName: 'Arial', fontSize: 16}},
            chartArea:{left: 0,top: 0,width: "100%",height: "100%"},
            enableInteractivity: false/*,
            animation: { duration: 1000, easing: 'out' }*/
        };

        chart2 = new google.visualization.PieChart(document.getElementById('grafico-aperte'));
        chart2.draw(data2, options2);

问题出现在OS / Web浏览器上。 我不知道这是否是可视化API的错误,还是我错过了什么?

解决!!:

不要问我为什么,但如果我按照以下方式(使用javascript Number()函数)放置数据,它可以工作:

        var data2 = google.visualization.arrayToDataTable([
            ['Tipo', 'Valore'],
            ['Aperte', Number(unique_opened)],
            ['Non aperte', Number(combined1)]
        ]);

1 个答案:

答案 0 :(得分:1)

我不知道这是不是你的情况,但你可以用以下方式产生这样的半圆。你的代码几乎没有变化(只有第二部分):

var unique_opened = 5.555; // real value: 11.11;
var combined1 = 44.445;  //   real value: 88.89;
var noshow = 50;

....
    var data2 = google.visualization.arrayToDataTable([
        ['Tipo', 'Valore'],
        ['Aperte', unique_opened],
        ['Non aperte', combined1],
        ['noshow', noshow]
    ]);

    options2 = {
        width: 250,
        height: 250,
        pieHole: 0.5,
        colors: ['#3e9ca8','#ff5932', '#ffffff'],
    ...

你得到:

enter image description here

Javier González的想法