简体   繁体   English

在Google Charts API中设置垂直轴比例

[英]setting the vertical axis scale in google charts api

I was playing around with trying to set the vertical axis scale in my google charts. 我在尝试在Google图表中设置垂直轴比例。 I'm not happy with the auto scaling that it does since I have two results and want to see them on an even scale for apples-to-apples comparison. 我对自动缩放功能不满意,因为我有两个结果,希望看到它们能以均匀的比例进行苹果之间的比较。

This is my code. 这是我的代码。 I have set the max and min values, yet that does not seem to apply in the output. 我已经设置了最大值和最小值,但是这似乎不适用于输出。

Code

function createExpenseChart(data) {
        google.load("visualization", "1", {packages:["corechart"]});

        var chartdata = new google.visualization.DataTable();

    chartdata.addColumn('number', 'Expense');
    chartdata.addColumn('number', '2013');
        chartdata.addColumn('number', '2014');

        for (var k in data["Expense"]["2013"]){
            if (data["Expense"]["2013"].hasOwnProperty(k)) {
["2013"][k],10),parseInt(data["Expense"]["2014"][k],10)])
                chartdata.addRow([parseInt(k,10),parseInt(data["Expense"]["2013"][k],10),parseInt(data["Expense"]["2014"][k],10)]);
            }
        }

    var options = {'title':'2013 vs. 2014 comparison,
                curveType: 'function',

viewWindowMode:'explicit',
              viewWindow:{
                max:100000,
                min:10000
        },
        vAxis: {title: 'Cost ($)',
                        minValue: 0,
                },
        hAxis: {title: 'Expense (dollars)'},
        height: 600,
        width: 1000
    };

    var chart = new google.visualization.LineChart(document.getElementById('mydiv'));
    chart.draw(chartdata, options);
}

I have also tried the following, but they don't show any effect 我也尝试了以下方法,但是它们没有显示任何效果

var options = {'title':'2013 v/s 2014',
                curveType: 'function',

viewWindowMode:'explicit',
              viewWindow:{
                max:80,
                min:20
        },
vAxis: {
title: 'Cost ($)'
    viewWindowMode:'explicit',
    viewWindow: {
        max:10000,
        min:10000
    }
},
        hAxis: {title: 'Expense (dollars)'},
        height: 600,
        width: 1000
    };

Sorry guys, this is resolved. 抱歉,这已解决。 Pretty much the same code worked me. 几乎相同的代码对我有效。 I just had to clean my cache. 我只需要清理缓存。

Sorry for the confusion. 对困惑感到抱歉。

function createExpenseChart(data) {
        google.load("visualization", "1", {packExpenses:["corechart"]});

        var chartdata = new google.visualization.DataTable();

    chartdata.addColumn('number', 'Expense');
    chartdata.addColumn('number', 'Previous Cost');
        chartdata.addColumn('number', '2014 Cost');

        for (var k in data["Expense"]["2013"]){
            if (data["Expense"]["2013"].hasOwnProperty(k)) {
                //console.log([parseInt(k,10),parseInt(data["Expense"]["2013"][k],10),parseInt(data["Expense"]["2014"][k],10)])
                chartdata.addRow([parseInt(k,10),parseInt(data["Expense"]["2013"][k],10),parseInt(data["Expense"]["2014"][k],10)]);
            }
        }

    var formatter = new google.visualization.NumberFormat({negativeColor: 'red', negativeParens: true, pattern: '$###,###'});
    formatter.format(chartdata, 1);
    formatter.format(chartdata, 2);

    var options = {'title':'2013 vs. 2014 Costs by Expense',
                curveType: 'function',
                viewWindowMode:'explicit',
                viewWindow:{
                        min:0
        },
        vAxis: {title: 'Cost ($)',
                viewWindowMode : 'explicit',
                viewWindow:
                {
                        min: 0,
                        max:42000000
                }
                },
        hAxis: {title: 'Expense (years)'},
        height: 600,
        width: 1000
    };

    var chart = new google.visualization.LineChart(document.getElementById('Expensecostdiv'));
    chart.draw(chartdata, options);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM