Skip to content

Instantly share code, notes, and snippets.

@vongrippen
Created October 30, 2012 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vongrippen/3982741 to your computer and use it in GitHub Desktop.
Save vongrippen/3982741 to your computer and use it in GitHub Desktop.
$(document).ready(function () {
var ticks = [
<% current_account.projects.each do |project| %>
'<%= project.tracker_project %>',
<% end %>
];
var data = [
<% new_exceptions, repeat_exceptions = [], [] %>
<%
current_account.projects.each do |project|
new_exceptions << project.exception_reports.new_exceptions.count || 0
repeat_exceptions << project.exception_reports.repeat_exceptions.count || 0
end
%>
[
<% new_exceptions.each do |e| %>
'<%= e %>',
<% end %>
],
[
<% repeat_exceptions.each do |e| %>
'<%= e %>',
<% end %>
]
];
<%
max = 0
current_account.projects.each do |p|
if p.exception_reports.new_exceptions.count > max
max = p.exception_reports.new_exceptions.count
end
if p.exception_reports.repeat_exceptions.count > max
max = p.exception_reports.repeat_exceptions.count
end
end
%>
var plot1 = $.jqplot('bar-chart', data, {
// The "seriesDefaults" option is an options object that will
// be applied to all series in the chart.
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
rendererOptions:{fillToZero:true}
},
// Custom labels for the series are specified with the "label"
// option on the series option. Here a series option object
// is specified for each series.
series:[
{label:'New Exceptions'},
{label:'Repeat Exceptions'}
],
seriesColors: ["#F90", "#3C4049"],
// Show the legend and put it outside the grid, but inside the
// plot container, shrinking the grid to accomodate the legend.
// A value of "outside" would not shrink the grid and allow
// the legend to overflow the container.
legend:{
show:true,
placement:'insideGrid'
},
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
tickOptions: {
angle: -35,
fontSize: '10pt'
}
},
axes:{
// Use a category axis on the x axis and use our custom ticks.
xaxis:{
renderer:$.jqplot.CategoryAxisRenderer,
ticks:ticks
},
// Pad the y axis just a little so bars can get close to, but
// not touch, the grid boundaries. 1.2 is the default padding.
yaxis:{
pad:1.05,
tickOptions:{formatString:'%d'},
min:0,
max: <%= max + 1 %>
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment