首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google图表中的Y轴在"General 1,General 2“等中递增- Java脚本

Google图表中的Y轴在"General 1,General 2“等中递增- Java脚本
EN

Stack Overflow用户
提问于 2015-04-09 15:59:27
回答 1查看 1.1K关注 0票数 3

我在Google上的仪表板有问题。目前,除了列图表在Y轴上显示字符串而不是整数外,一切都正常工作。

我发现Google图表页面上的文档很难理解,所以如果我的代码中有错误,或者如果有一种更简单的方法,我很抱歉。

我的JS如下所示:https://jsfiddle.net/hm7q5peg/6/

代码语言:javascript
复制
    google.load('visualization', '1.0', {
    'packages': ['corechart','table', 'controls']
});
google.setOnLoadCallback(drawDashboard);

function drawDashboard() {
    // Using the jsapi, it's better to set the url
    // for the spreadsheet, then use setQuery() to
    // define the query that will provide your data.
    var url = '//docs.google.com/spreadsheet/ccc?key=1FOVmfesx7ATNe8qjWjkU2GbjBCBZxL0BRswJv6rcGPs&usp=drive_web&gid=1324373577';

    var query = new google.visualization.Query(url);
    query.setQuery('select B,C where B <> ""');

    // Send the query with a callback function
    query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
    // Called when the query response is returned.
    if (response.isError()) {
        alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
        return;
    }

    var data = response.getDataTable();

    var dashboard = new google.visualization.Dashboard(
    document.getElementById('dashboard_div'));

    // Create a range slider, passing some options
    var donutRangeSlider = new google.visualization.ControlWrapper({
        'controlType': 'NumberRangeFilter',
            'containerId': 'filter_div',
            'options': {
            'filterColumnLabel': 'Number Attended'
        }
    });


    // Create a pie chart, passing some options
    var pieChart = new google.visualization.ChartWrapper({
        'chartType': 'PieChart',
            'containerId': 'chart_div',
            'options': {
            'width': 300,
                'height': 300,
                'pieSliceText': 'value',
                'legend': 'right'
        }
    });

        //define a table
    var table = new google.visualization.ChartWrapper({
        'chartType': 'Table',
        'containerId': 'table_div',
        'options': {
            'width':'300px'
        }
    });

    //define the column chart
    var columnChart = new google.visualization.ChartWrapper({
        'chartType': 'ColumnChart',
        'containerId' : 'column_div',
    });

    // Establish dependencies, declaring that 'filter' drives 'pieChart',
    // so that the pie chart will only display entries that are let through
    // given the chosen slider range.
    dashboard.bind(donutRangeSlider, [pieChart, table, columnChart]);

    // Draw the dashboard.
    dashboard.draw(data);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-09 20:42:21

如果您还没有这样做,请查看ColumnChart配置选项,看看您必须使用什么。通过为垂直轴指定数字格式,您将得到数字。不幸的是,如果没有一堆附加代码,gViz将决定您必须要看到分数,即使您的数据都是整数。

更新的jsFiddle

代码语言:javascript
复制
//define the column chart
var columnChart = new google.visualization.ChartWrapper({
    'chartType': 'ColumnChart',
    'options' : {
        'hAxis' : { 'title' : 'Student Name' },
        'legend' : {position: 'none' },
        'vAxis' : {format: 'short',
                   title: 'Number Attended'}
     },
    'containerId' : 'column_div',
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29543417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档