【问题标题】:Google Visualization API Format Secondary Y-axis different from Primary Y-AxisGoogle Visualization API 格式辅助 Y 轴与主 Y 轴不同
【发布时间】:2012-08-07 19:25:01
【问题描述】:

我有一些数据正在尝试使用 Google 可视化 API(Google 图表工具)显示。我已经能够创建图表,它看起来很棒,除了辅助 Y 轴应该显示为百分比而不是常规数字。这是我的代码和生成的图像。

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

function drawVisualization() {
    //Some raw data (not necessarily accurate)'
    var data = google.visualization.arrayToDataTable([
        ['AuditPeriod', 'Audit Count', 'Fail Percentage'],
        ['02-11-2012',  0,      0],
        ['02-18-2012',  0,      0],
        ['02-25-2012',  0,      0],
        ...
        ['07-21-2012',  1476,   .233062],
        ['07-28-2012',  1651,   .253180],
        ['08-04-2012',  2217,   .210645]
    ]);

    var options = {
        vAxis: [0: {format: '#,###'}, 1: {format: '#%'}],
        hAxis: { title: "Week", format: 'm/d/y'},
        series: {
            0:{ type: "bars", targetAxisIndex: 0 },
            1: { type: "line", targetAxisIndex: 1}
        }
    }

    var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
    chart.draw(data, options);
}        
google.setOnLoadCallback(drawVisualization);

如果我设置vAxis:{format: '#%'},那么两个轴都被格式化为我不想要的百分比。有没有办法将第二个轴的格式与第一个轴不同?

【问题讨论】:

标签: google-visualization


【解决方案1】:

把这个问题发到Google Visualization Group,得到了答案。

胆小

你几乎拥有它,在格式化多个轴时使用 vAxes 而不是 vAxis:

vAxes:{ 0:{格式:'#,###'}, 1:{格式:'#%'} }​

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    • 1970-01-01
    • 2020-03-28
    相关资源
    最近更新 更多