删除Google可视化饼图中的图例

时间:2015-02-21 18:44:30

标签: javascript charts google-visualization

我想在饼图中隐藏标签。我认为正确的词是标签?但我可能是错的。基本上我有一个饼图显示一些数据,饼图外面有一个带有颜色立方体的标签,旁边有一个显示每种颜色代表的名称,我想摆脱它,因为在悬停时我显示相同的数据,它占用了我想要使用的一些有价值的房地产。这是我的Javascript代码:

 google.load("visualization", "1", { packages: ["corechart"] });
    google.setOnLoadCallback(drawChart);

    function drawChart() {
        var options = {
            title: '',
            is3D: true
        };
        $.ajax({
            type: "POST",
            url: "myPage.aspx/GetChartData",
            data: '{}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {
                //console.log(JSON.stringify(r))
                var data = google.visualization.arrayToDataTable(r.d);
                var chart = new google.visualization.PieChart($("#chart")[0]);
                var formatter = new google.visualization.NumberFormat(
  { negativeColor: 'red', negativeParens: true, pattern: '$###,###.##' });
                formatter.format(data, 1);
                chart.draw(data, options);
            },
            failure: function (r) {
                alert(r.d);
            },
            error: function (r) {
                alert(r.d);
            }
        });
    }

1 个答案:

答案 0 :(得分:2)

Google图表可视化,杀死传奇:

legend: {position: 'none'} 

- 这将取消Google Charts中的图例。

另外,JS要这样做:

http://jsfiddle.net/api/post/library/pure/

legend: 'none'

所以,最终这应该为你做到:

google.load("visualization", "1", { packages: ["corechart"] });
    google.setOnLoadCallback(drawChart);

    function drawChart() {
        var options = {
            title: '',
            is3D: true,
            legend: none,
        };
        $.ajax({
            type: "POST",
            url: "myPage.aspx/GetChartData",
            data: '{}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {
                //console.log(JSON.stringify(r))
                var data = google.visualization.arrayToDataTable(r.d);
                var chart = new google.visualization.PieChart($("#chart")[0]);
                var formatter = new google.visualization.NumberFormat(
  { negativeColor: 'red', negativeParens: true, pattern: '$###,###.##' });
                formatter.format(data, 1);
                chart.draw(data, options);
            },
            failure: function (r) {
                alert(r.d);
            },
            error: function (r) {
                alert(r.d);
            }
        });
    }