From 6f517ac88a51964c36b2de3d0dfe0cb551dd0e6c Mon Sep 17 00:00:00 2001 From: davidcys Date: Tue, 29 Oct 2013 00:15:18 +0800 Subject: [PATCH] adding column and pie charts, TODO:update readme --- app/views/rails_admin/main/_chart.html.erb | 16 ++++++++++++++-- lib/rails_admin_charts.rb | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/views/rails_admin/main/_chart.html.erb b/app/views/rails_admin/main/_chart.html.erb index 14a6075..7fc160b 100644 --- a/app/views/rails_admin/main/_chart.html.erb +++ b/app/views/rails_admin/main/_chart.html.erb @@ -4,7 +4,10 @@ $(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 %>' @@ -20,6 +23,7 @@ }, <% 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 %> @@ -58,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' diff --git a/lib/rails_admin_charts.rb b/lib/rails_admin_charts.rb index f9720b4..6ec5fac 100644 --- a/lib/rails_admin_charts.rb +++ b/lib/rails_admin_charts.rb @@ -36,6 +36,10 @@ def xaxis def label_rotation "0" end + + def chart_type + "" + end end end