diff --git a/Pearlception/Gemfile b/Pearlception/Gemfile index eef33ba..b20fc1a 100644 --- a/Pearlception/Gemfile +++ b/Pearlception/Gemfile @@ -20,6 +20,7 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby +gem 'chart-js-rails' # Use jquery as the JavaScript library gem 'jquery-rails' diff --git a/Pearlception/Gemfile.lock b/Pearlception/Gemfile.lock index 25d69d9..7a43b2b 100644 --- a/Pearlception/Gemfile.lock +++ b/Pearlception/Gemfile.lock @@ -53,6 +53,8 @@ GEM bootstrap-popover-rails (0.1.0) builder (3.2.2) byebug (9.0.6) + chart-js-rails (0.1.2) + railties (> 3.1) coderay (1.1.1) coffee-rails (4.2.1) coffee-script (>= 2.2.0) @@ -213,6 +215,7 @@ DEPENDENCIES bcrypt (~> 3.1.7) bootstrap-popover-rails byebug + chart-js-rails coffee-rails (~> 4.2) devise hirb diff --git a/Pearlception/app/assets/javascripts/application.js b/Pearlception/app/assets/javascripts/application.js index fe47c91..ee26e7b 100644 --- a/Pearlception/app/assets/javascripts/application.js +++ b/Pearlception/app/assets/javascripts/application.js @@ -15,3 +15,4 @@ //= require turbolinks //= require bootstrap/bootstrap-rails-tooltip //= require bootstrap/bootstrap-rails-popover +//= require Chart diff --git a/Pearlception/app/assets/javascripts/statistics.coffee b/Pearlception/app/assets/javascripts/statistics.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/Pearlception/app/assets/javascripts/statistics.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/Pearlception/app/assets/javascripts/statistics.js b/Pearlception/app/assets/javascripts/statistics.js new file mode 100644 index 0000000..988b00f --- /dev/null +++ b/Pearlception/app/assets/javascripts/statistics.js @@ -0,0 +1,37 @@ +var ctx = document.getElementById("gradesChart"); +var myChart = new Chart(ctx, { + type: 'bar', + data: { + labels: ["Grade1", "Grade2", "Grade3", "Grade4", "Grade5", "Grade6"], + datasets: [{ + label: 'Count for each grade', + data: [12, 19, 3, 5, 2, 3], + backgroundColor: [ + 'rgba(255, 99, 132, 0.2)', + 'rgba(54, 162, 235, 0.2)', + 'rgba(255, 206, 86, 0.2)', + 'rgba(75, 192, 192, 0.2)', + 'rgba(153, 102, 255, 0.2)', + 'rgba(255, 159, 64, 0.2)' + ], + borderColor: [ + 'rgba(255,99,132,1)', + 'rgba(54, 162, 235, 1)', + 'rgba(255, 206, 86, 1)', + 'rgba(75, 192, 192, 1)', + 'rgba(153, 102, 255, 1)', + 'rgba(255, 159, 64, 1)' + ], + borderWidth: 1 + }] + }, + options: { + scales: { + yAxes: [{ + ticks: { + beginAtZero:true + } + }] + } + } +}); diff --git a/Pearlception/app/assets/stylesheets/statistics.scss b/Pearlception/app/assets/stylesheets/statistics.scss index 8ccb962..b05be63 100644 --- a/Pearlception/app/assets/stylesheets/statistics.scss +++ b/Pearlception/app/assets/stylesheets/statistics.scss @@ -1,3 +1,7 @@ // Place all the styles related to the statistics controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ +#myChart{ + width:100%; + height: 100%; +} diff --git a/Pearlception/app/views/statistics/index.html.erb b/Pearlception/app/views/statistics/index.html.erb index 882d686..0940def 100644 --- a/Pearlception/app/views/statistics/index.html.erb +++ b/Pearlception/app/views/statistics/index.html.erb @@ -47,5 +47,17 @@ +