Đây là những gì tôi đã làm trong dự án của tôi cách đây 4 tháng. Chú ý rất chặt chẽ đến mã. Nếu bạn đang sử dụng ruby trên đường ray, bạn có thể lấy dữ liệu từ bộ điều khiển bằng cách gõ <% = @get_data_from_controller_here này%>
<html>
<head>
<title></title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart1);
google.setOnLoadCallback(drawChart2);
function drawChart1() {
var data = google.visualization.arrayToDataTable([
['Work', <%= @get_data_from_controller_here1 %>],
['Eat', <%= @get_data_from_controller_here2 %>],
['Commute', <%= @get_data_from_controller_here3 %>],
['Watch TV', <%= @get_data_from_controller_here4 %>],
['Sleep', <%= @get_data_from_controller_here5 %>]
]);
var options = {
title: 'My Daily Activities',
chartArea:{left:5, top:20,width:"100%",height:"100%"},
height: 500,
width: 500,
is3D: true
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d1'));
chart.draw(data, options);
}
function drawChart2() {
var data = google.visualization.arrayToDataTable([
['Work', <%= @get_data_from_controller_here11 %>],
['Eat', <%= @get_data_from_controller_here22 %>],
['Commute', <%= @get_data_from_controller_here33 %>],
['Watch TV', <%= @get_data_from_controller_here44 %>],
['Sleep', <%= @get_data_from_controller_here55 %>]
]);
var options = {
title: 'My Daily Activities',
chartArea:{left:5, top:20, width:"100%",height:"100%"},
height: 500,
width: 500,
is3D: true
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d2'));
chart.draw(data, options);
}
</script>
</head>
<body>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#OpenDialog").click(function() {
$('#dialog').css('overflow', 'hidden')
$("#dialog").dialog({modal: true,
height: 450,
width: 850,
resizable: true
});
});
});
</script>
<a id="OpenDialog" style="display:inline-block;" href="#" >Click here to open dialog</a>
<div id="dialog" title="Dialog Title" style="display:none; overlay:hidden">
<div id="piechart_3d1" style="width: 49%; height:49%; float:left;"></div>
<div id="piechart_3d2" style="width: 49%; height:49%; float:right;"></div>
</div>
</body>