Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into david-cys-master
  • Loading branch information
pgeraghty committed Dec 27, 2013
2 parents 6e9e2aa + 6f517ac commit 480f8d8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,21 @@ The data displayed in the chart can be altered by overriding the class method `g
end
```

You can set custom categories by overriding the method `xaxis`

```ruby
def self.xaxis
['cat a', 'cat b', 'cat c' 'cat d', 'cat e', 'cat f', 'cat g', 'cat h']
end
```

You can set label rotation by overriding the method `label_rotation`
It expects a string `-45` or `-90`

```ruby
def self.label_rotation
"-45"
end
```

This project uses MIT-LICENSE.
46 changes: 36 additions & 10 deletions app/views/rails_admin/main/_chart.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,43 @@
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'growth_rate'
<% if @abstract_model.model.chart_type == "column" %>
type: 'column',
<% end %>
renderTo: 'growth_rate'
},
title: {
text: '<%= @abstract_model.to_s.pluralize %>'
},
xAxis: {
type: 'datetime'
labels: {
<% if @abstract_model.model.label_rotation == "-45" %>
rotation: -45,
<% elsif @abstract_model.model.label_rotation == "-90" %>
rotation: -90,
<% end %>
align: 'right'
},
<% if @abstract_model.model.xaxis == "datetime" %>
type: 'datetime'
<% elsif @abstract_model.model.chart_type == "pie" %>
<% else %>
categories: <%=raw @abstract_model.model.xaxis.to_json %>
<% end %>

},

// yAxis: {
// title: {
// text: 'Counts'
// }
// },
tooltip: {
formatter: function() {
return ''+
Highcharts.dateFormat('%e. %b', this.x) +' -> '+ this.y;
}
},
<%#tooltip: {%>
<%#formatter: function() {%>
<%#return ''+%>
<%#Highcharts.dateFormat('%e. %b', this.x) +' -> '+ this.y;%>
<%#}%>
<%#},%>
plotOptions: {
spline: {
lineWidth: 4,
Expand All @@ -44,7 +62,15 @@
}
}
},
series: <%=raw @abstract_model.model.graph_data(100.days.ago).to_json %>,
<% if @abstract_model.model.chart_type == "pie" %>
series: [{
type: 'pie',
name: 'Number of <%= @abstract_model.to_s.pluralize %>',
data: <%=raw @abstract_model.model.graph_data(100.days.ago).to_json %>
}],
<% else %>
series: <%=raw @abstract_model.model.graph_data(100.days.ago).to_json %>,
<% end %>
navigation: {
menuItemStyle: {
fontSize: '10px'
Expand All @@ -53,4 +79,4 @@
});
});
});
</script>
</script>
12 changes: 12 additions & 0 deletions lib/rails_admin_charts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def graph_data(since=30.days.ago)
}
]
end

def xaxis
"datetime"
end

def label_rotation
"0"
end

def chart_type
""
end
end
end

Expand Down

0 comments on commit 480f8d8

Please sign in to comment.