Skip to content

Instantly share code, notes, and snippets.

@vumanhcuongit
Last active December 16, 2015 09:38
Show Gist options
  • Save vumanhcuongit/5414121 to your computer and use it in GitHub Desktop.
Save vumanhcuongit/5414121 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
google.load('visualization', '1.0', {'packages':["imagechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
// Create and populate the data table.
var today_electricity_cost = <%= number_with_precision(Calc.today_avg_electricity_cost_of_lighting(@location), :precision => 2) %>
var sum_lamp_maint = <%= number_with_precision(Calc.sum_lamp_maint_saving_per_month(@location), :precision => 2) %>
var sum_total_savings = <%= number_with_precision(Calc.sum_total_savings_month(@location), :precision => 2) %>
var data = google.visualization.arrayToDataTable([
['Today', 'Average monthly electricity cost of lighting ($'+today_electricity_cost+')', 'Average monthly lamp maintenance cost ($'+sum_lamp_maint+')', 'Average monthly cost of ballast mainteance ($'+sum_total_savings+')'],
['Today', today_electricity_cost, sum_lamp_maint, sum_total_savings]
]);
var options = {};
options.cht = 'bhs';
options.chds = 'a';
options.chxr = 'a';
//options.chm = 'N*cUSD*,FFFFFF,0,,16,,c|N*cUSD*,FFFFFF,1,,16,,c|N*cUSD*,FFFFFF,2,,16,,c';
options.chs = '1000x200';
//options.chco = 'E7FFFF,13829D,84D5D'
options.chco = '35B1CB,13829D,084D5D'
// Create and draw the visualization.
new google.visualization.ImageChart(document.getElementById('visualization')).
draw(data, options);
// START CHART 2
var sum_kwh_month_old = <%= number_with_precision(Calc.sum_kwh_month_old(@location), :precision => 2) %>
var sum_kwh_month_new = <%= number_with_precision(Calc.sum_kwh_month_new(@location), :precision => 2) %>
data = google.visualization.arrayToDataTable([
['Name', ''],
['Today', sum_kwh_month_old ],
['w/ Ahkeo Electric', sum_kwh_month_new ]
]);
var options = {};
options.cht = 'bvg';
var min = 0;
var max = Math.max(sum_kwh_month_old, sum_kwh_month_new ) + 200; // SET BANG MAX(Today, Ahkeo) + 200
options.chds = 'a';
var meters = 'N*s';
var color = '000000';
var index = 0;
var allbars = -1;
var fontSize = 14;
var priority = 0;
options.chm = [meters, color, index, allbars, fontSize, priority].join(',');
options.chco= '084D5D|35B1CB';
options.chs= '400x325';
//options.chtt= 'KILOWATT HOURS/MONTH'
//options.chts= '5FA7B3,20'
new google.visualization.ImageChart(document.getElementById('column_chart')).
draw(data, options);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment