2013-07-23 49 views
1

如何使用ChartWrapper和格式化程序爲線條/條形圖上的工具提示添加後綴? 這是我對ChartWrapperGoogle Charts:ChartWrapper和格式化程序(NumberFormat)

function drawChartb() { 

    var wrapper = new google.visualization.ChartWrapper({ 
    chartType: 'LineChart', 
    dataTable: [['Person', 'Score'], [1, .50], [2, .25]], 
    options: {'legend': 'bottom', 'colors': ['#D70005'], 'chartArea': {left: 40, top: 10, width: 450}, 'vAxis': {format: '#,###%', 'viewWindow': {max: 1.05, min: .2}}, 'pointSize': 6}, 
    containerId: 'chart_div' 
    }); 

    wrapper.draw(); 
} 

代碼這是我做到了不使用chartwrapper。

// set tooltip as percentage 
var formatter = new google.visualization.NumberFormat({ 
pattern: '#%', 
fractionDigits: 2 
}); 
formatter.format(data, 1); 

感謝

回答

6

可以定義包裝之外的數據,使用就可以了formatter,然後設置DataTable中等於該數據源:

function drawVisualization() { 

    var data = google.visualization.arrayToDataTable([ 
     ['Person', 'Score'], [1, .50], [2, .25] 
    ]); 

    // set tooltip as percentage 
    var formatter = new google.visualization.NumberFormat({ 
    pattern: '#%', 
    fractionDigits: 2 
    }); 
    formatter.format(data, 1); 

    var wrapper = new google.visualization.ChartWrapper({ 
    chartType: 'LineChart', 
    dataTable: data, 
    options: {'legend': 'bottom', 'colors': ['#D70005'], 'chartArea': {left: 40, top: 10, width: 450}, 'vAxis': {format: '#,###%', 'viewWindow': {max: 1.05, min: .2}}, 'pointSize': 6}, 
    containerId: 'visualization' 
    }); 


    wrapper.draw(); 
} 

結果:

Sample Image

+0

好主意使用陣列組合yToDataTable和ChartWrapper。謝謝 –

相關問題