Module: Chart2Helper

Defined in:
app/helpers/chart2_helper.rb

Instance Method Summary collapse

Instance Method Details

#chart2_bar(id = nil, size = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/chart2_helper.rb', line 43

def chart2_bar id=nil, size=nil
  html = "<canvas id=\"myChart_bar\" width=\"400\" height=\"400\"></canvas>".html_safe
  script = javascript_tag do
    <<-END.html_safe
    var ctx = document.getElementById("myChart_bar");

    var data = {
  labels: ["January", "February", "March", "April", "May", "June", "July"],
  datasets: [
      {
          label: "My First dataset",
          backgroundColor: "rgba(255,99,132,0.2)",
          borderColor: "rgba(255,99,132,1)",
          borderWidth: 1,
          hoverBackgroundColor: "rgba(255,99,132,0.4)",
          hoverBorderColor: "rgba(255,99,132,1)",
          data: [65, 59, 80, 81, 56, 55, 40],
      }
  ]
};

var options = {};

var myBarChart = new Chart(ctx, {
  type: 'bar',
  data: data,
  options: options
});

    END
  end
  return html + script
end

#chart2_donutObject



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'app/helpers/chart2_helper.rb', line 212

def chart2_donut
  html = "<canvas id=\"myChart_donut\" width=\"400\" height=\"400\"></canvas>".html_safe
  script = javascript_tag do
    <<-END.html_safe
    var ctx = document.getElementById("myChart_donut");

    var options = {};

    var data = {
  labels: [
      "Red",
      "Green",
      "Yellow"
  ],
  datasets: [
      {
          data: [300, 50, 100],
          backgroundColor: [
              "#FF6384",
              "#36A2EB",
              "#FFCE56"
          ],
          hoverBackgroundColor: [
              "#FF6384",
              "#36A2EB",
              "#FFCE56"
          ]
      }]
};


var options = {};

var myDonutChart = new Chart(ctx, {
type: 'doughnut',
  data: data,
  options: options
});
    END
  end
  return html + script
end

#chart2_line(id = nil, size = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/helpers/chart2_helper.rb', line 77

def chart2_line id=nil, size=nil
  html = "<canvas id=\"myChart_line\" width=\"400\" height=\"400\"></canvas>".html_safe
  script = javascript_tag do
    <<-END.html_safe
    var ctx = document.getElementById("myChart_line");

    var data = {
  labels: ["January", "February", "March", "April", "May", "June", "July"],
  datasets: [
      {
          label: "My First dataset",
          fill: false,
          lineTension: 0.1,
          backgroundColor: "rgba(75,192,192,0.4)",
          borderColor: "rgba(75,192,192,1)",
          borderCapStyle: 'butt',
          borderDash: [],
          borderDashOffset: 0.0,
          borderJoinStyle: 'miter',
          pointBorderColor: "rgba(75,192,192,1)",
          pointBackgroundColor: "#fff",
          pointBorderWidth: 1,
          pointHoverRadius: 5,
          pointHoverBackgroundColor: "rgba(75,192,192,1)",
          pointHoverBorderColor: "rgba(220,220,220,1)",
          pointHoverBorderWidth: 2,
          pointRadius: 1,
          pointHitRadius: 10,
          data: [65, 59, 80, 81, 56, 55, 40],
      }
  ]
};

var options = {};

var myLineChart = new Chart(ctx, {
  type: 'line',
  data: data,
  options: options
});
    END
  end
  return html + script
end

#chart2_pie(id = nil, size = nil) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'app/helpers/chart2_helper.rb', line 168

def chart2_pie id=nil, size=nil
  html = "<div style=\"width: #{size[:width]}px; height: #{size[:height]}px;\"><canvas id=\"myChart_pie_#{id}\" width=\"#{size[:width]}\" height=\"#{size[:height]}\"></canvas></div>".html_safe
  script = javascript_tag do
    <<-END.html_safe
    var ctx = document.getElementById("myChart_pie_#{id}");

    var options = {};

    var data = {
  labels: [
      "Red",
      "Green",
      "Yellow"
  ],
  datasets: [
      {
          data: [300, 50, 100],
          backgroundColor: [
              "#FF6384",
              "#36A2EB",
              "#FFCE56"
          ],
          hoverBackgroundColor: [
              "#FF6384",
              "#36A2EB",
              "#FFCE56"
          ]
      }]
};


var options = {};

var myPieChart = new Chart(ctx, {
  type: 'pie',
  data: data,
  options: options
});

    END
  end
  return html + script
end

#chart2_polar_areaObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'app/helpers/chart2_helper.rb', line 255

def chart2_polar_area
  html = "<canvas id=\"myChart_polarArea\" width=\"400\" height=\"400\"></canvas>".html_safe
  script = javascript_tag do
    <<-END.html_safe

    var ctx = document.getElementById("myChart_polarArea");

    var options = {};

    var data = {
  labels: [
      "Red",
      "Green",
      "Yellow"
  ],
  datasets: [
      {
          data: [300, 50, 100],
          backgroundColor: [
              "#FF6384",
              "#36A2EB",
              "#FFCE56"
          ],
          hoverBackgroundColor: [
              "#FF6384",
              "#36A2EB",
              "#FFCE56"
          ]
      }]
};


var options = {};

var myPolarAreaChart = new Chart(ctx, {
type: 'polarArea',
  data: data,
  options: options
});
    END
  end
  return html + script
end

#chart2_radar(id = nil, size = nil) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/helpers/chart2_helper.rb', line 122

def chart2_radar id=nil, size=nil
  html = "<div style=\"width: #{size[:width]}px; height: #{size[:height]}px;\"><canvas id=\"myChart_radar_#{id}\" width=\"#{size[:width]}\" height=\"#{size[:height]}\"></canvas></div>".html_safe
  script = javascript_tag do
    <<-END.html_safe

    var ctx = document.getElementById("myChart_radar_#{id}");

    var data = {
        labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
        datasets: [
            {
                label: "My First dataset",
                backgroundColor: "rgba(179,181,198,0.2)",
                borderColor: "rgba(179,181,198,1)",
                pointBackgroundColor: "rgba(179,181,198,1)",
                pointBorderColor: "#fff",
                pointHoverBackgroundColor: "#fff",
                pointHoverBorderColor: "rgba(179,181,198,1)",
                data: [65, 59, 90, 81, 56, 55, 40]
            },
            {
                label: "My Second dataset",
                backgroundColor: "rgba(255,99,132,0.2)",
                borderColor: "rgba(255,99,132,1)",
                pointBackgroundColor: "rgba(255,99,132,1)",
                pointBorderColor: "#fff",
                pointHoverBackgroundColor: "#fff",
                pointHoverBorderColor: "rgba(255,99,132,1)",
                data: [28, 48, 40, 19, 96, 27, 100]
            }
        ]
    };

    var options = {};

    var myRadarChart = new Chart(ctx, {
        type: 'radar',
        data: data,
        options: options
    });

    END
  end
  return html + script
end

#stackedbarObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/chart2_helper.rb', line 2

def stackedbar 
  html = "<canvas id=\"myChart_bar\" width=\"400\" height=\"400\"></canvas>".html_safe
  script = javascript_tag do
    <<-END.html_safe

    var ctx = document.getElementById("myChart_bar");
          var data = {
          labels: ["January", "February", "March", "April", "May", "June", "July"],
          datasets: [
              {
                  label: "My First dataset",
                  backgroundColor: "rgba(255,99,132,0.2)",
                  borderColor: "rgba(255,99,132,1)",
                  borderWidth: 1,
                  hoverBackgroundColor: "rgba(255,99,132,0.4)",
                  hoverBorderColor: "rgba(255,99,132,1)",
                  data: [65, 59, 80, 81, 56, 55, 40],
              }
          ]
      };
      
      var stackedBar = new Chart(ctx, {
          type: 'bar',
          data: data,
          options: {
              scales: {
                  xAxes: [{
                      stacked: true
                  }],
                  yAxes: [{
                      stacked: true
                  }]
              }
          }
      });

    END
  end
  return html + script
end