apexcharts 0.1.5 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +456 -38
- data/lib/apex_charts/charts.rb +16 -0
- data/lib/{apexcharts/charts/area.rb → apex_charts/charts/area_chart.rb} +1 -1
- data/lib/{apexcharts/charts/bar.rb → apex_charts/charts/bar_chart.rb} +1 -1
- data/lib/apex_charts/charts/base_chart.rb +37 -0
- data/lib/apex_charts/charts/bubble_chart.rb +13 -0
- data/lib/{apexcharts/charts/candlestick.rb → apex_charts/charts/candlestick_chart.rb} +1 -1
- data/lib/apex_charts/charts/cartesian_chart.rb +82 -0
- data/lib/{apexcharts/charts/column.rb → apex_charts/charts/column_chart.rb} +3 -1
- data/lib/{apexcharts/charts/donut.rb → apex_charts/charts/donut_chart.rb} +1 -2
- data/lib/{apexcharts → apex_charts}/charts/features/annotations.rb +22 -21
- data/lib/{apexcharts → apex_charts}/charts/features/mixable.rb +2 -3
- data/lib/{apexcharts/charts/heatmap.rb → apex_charts/charts/heatmap_chart.rb} +3 -5
- data/lib/{apexcharts/charts/line.rb → apex_charts/charts/line_chart.rb} +1 -1
- data/lib/apex_charts/charts/mixed_charts.rb +101 -0
- data/lib/{apexcharts/charts/pie.rb → apex_charts/charts/pie_chart.rb} +1 -2
- data/lib/apex_charts/charts/polar_chart.rb +9 -0
- data/lib/{apexcharts/charts/radar.rb → apex_charts/charts/radar_chart.rb} +3 -5
- data/lib/{apexcharts/charts/radial_bar.rb → apex_charts/charts/radial_bar_chart.rb} +1 -2
- data/lib/apex_charts/charts/range_bar_chart.rb +9 -0
- data/lib/{apexcharts/charts/scatter.rb → apex_charts/charts/scatter_chart.rb} +1 -1
- data/lib/apex_charts/charts/syncing_charts.rb +84 -0
- data/lib/apex_charts/colors.rb +27 -0
- data/lib/apex_charts/config/default_options.rb +16 -0
- data/lib/apex_charts/configuration.rb +25 -0
- data/lib/apex_charts/helper.rb +190 -0
- data/lib/apex_charts/options/annotations_options.rb +15 -0
- data/lib/apex_charts/options/chart_options.rb +32 -0
- data/lib/apex_charts/options/data_labels_options.rb +18 -0
- data/lib/apex_charts/options/div_attributes.rb +11 -0
- data/lib/apex_charts/options/fill_options.rb +14 -0
- data/lib/apex_charts/options/grid_options.rb +17 -0
- data/lib/apex_charts/options/legend_options.rb +32 -0
- data/lib/apex_charts/options/markers_options.rb +24 -0
- data/lib/apex_charts/options/no_data_options.rb +14 -0
- data/lib/apex_charts/options/plot_options.rb +16 -0
- data/lib/apex_charts/options/root_options.rb +47 -0
- data/lib/apex_charts/options/states_options.rb +11 -0
- data/lib/apex_charts/options/stroke_options.rb +14 -0
- data/lib/apex_charts/options/theme_options.rb +11 -0
- data/lib/apex_charts/options/title_subtitle_options.rb +15 -0
- data/lib/apex_charts/options/tooltip_options.rb +25 -0
- data/lib/apex_charts/options/x_axis_options.rb +26 -0
- data/lib/apex_charts/options/y_axis_options.rb +28 -0
- data/lib/{apexcharts → apex_charts}/options_builder.rb +95 -90
- data/lib/apex_charts/prefix_with_apex.rb +7 -0
- data/lib/apex_charts/prefixer.rb +21 -0
- data/lib/apex_charts/renderer.rb +113 -0
- data/lib/apex_charts/series.rb +7 -0
- data/lib/apex_charts/series/bubble_series.rb +50 -0
- data/lib/apex_charts/series/cartesian_series.rb +81 -0
- data/lib/apex_charts/series/polar_series.rb +48 -0
- data/lib/{apexcharts → apex_charts}/support/rails.rb +1 -1
- data/lib/apex_charts/support/sinatra.rb +9 -0
- data/lib/apex_charts/theme.rb +60 -0
- data/lib/{apexcharts → apex_charts}/utils.rb +1 -0
- data/lib/apex_charts/utils/copy.rb +11 -0
- data/lib/apex_charts/utils/date_time.rb +70 -0
- data/lib/{apexcharts → apex_charts}/utils/hash.rb +4 -3
- data/lib/{apexcharts → apex_charts}/version.rb +2 -1
- data/lib/apexcharts.rb +3 -2
- data/vendor/assets/javascripts/apexcharts.js +11 -3
- metadata +85 -65
- data/lib/apexcharts/charts.rb +0 -19
- data/lib/apexcharts/charts/base.rb +0 -34
- data/lib/apexcharts/charts/bubble.rb +0 -19
- data/lib/apexcharts/charts/cartesian.rb +0 -81
- data/lib/apexcharts/charts/mixed.rb +0 -85
- data/lib/apexcharts/charts/polar.rb +0 -14
- data/lib/apexcharts/charts/syncing.rb +0 -70
- data/lib/apexcharts/helper.rb +0 -109
- data/lib/apexcharts/options/annotations.rb +0 -10
- data/lib/apexcharts/options/axis.rb +0 -17
- data/lib/apexcharts/options/chart.rb +0 -26
- data/lib/apexcharts/options/data_labels.rb +0 -12
- data/lib/apexcharts/options/div_attributes.rb +0 -10
- data/lib/apexcharts/options/fill.rb +0 -12
- data/lib/apexcharts/options/grid.rb +0 -15
- data/lib/apexcharts/options/legend.rb +0 -24
- data/lib/apexcharts/options/markers.rb +0 -18
- data/lib/apexcharts/options/no_data.rb +0 -12
- data/lib/apexcharts/options/plot_options.rb +0 -12
- data/lib/apexcharts/options/root.rb +0 -42
- data/lib/apexcharts/options/states.rb +0 -9
- data/lib/apexcharts/options/stroke.rb +0 -12
- data/lib/apexcharts/options/subtitle.rb +0 -7
- data/lib/apexcharts/options/theme.rb +0 -8
- data/lib/apexcharts/options/title.rb +0 -13
- data/lib/apexcharts/options/tooltip.rb +0 -22
- data/lib/apexcharts/options/x_axis.rb +0 -12
- data/lib/apexcharts/options/y_axis.rb +0 -15
- data/lib/apexcharts/renderer.rb +0 -21
- data/lib/apexcharts/series.rb +0 -5
- data/lib/apexcharts/series/bubble.rb +0 -37
- data/lib/apexcharts/series/cartesian.rb +0 -65
- data/lib/apexcharts/series/polar.rb +0 -32
- data/lib/apexcharts/utils/date_time.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7da6c272c62c024c2e24180a80a69760efa4ba6703dd1fae81dc7119a2115ac1
|
4
|
+
data.tar.gz: 50bbebd360a73a13ebf328de39acef58d6c59270c136e58563eaa6f1a0764db8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de01a99814d9234441f6b4964239e9882f7676dd3749df05ffc995669a9bb74d4c29a57c4c839b37f9d2c675d0f8e72b8ad26f8d0f95d130a401777258c50f65
|
7
|
+
data.tar.gz: b57b96bc2bdcedadc007a093c7253a8ddb63d74dddbb58eb678e006e881a34d53ce26d1b623c7b25529845726832fd491c644b13ff3cf7a79794e8f5336f0834
|
data/README.md
CHANGED
@@ -1,19 +1,127 @@
|
|
1
1
|
<p align="center">
|
2
|
-
<img src="images/apexcharts.rb.png" height="
|
2
|
+
<img src="images/apexcharts.rb.png" height="150" />
|
3
3
|
</p>
|
4
4
|
|
5
5
|
<p align="center">
|
6
|
-
<a href="https://
|
7
|
-
|
8
|
-
|
6
|
+
<a href="https://rubygems.org/gems/apexcharts">
|
7
|
+
<img src="https://img.shields.io/gem/v/apexcharts.svg?label=apexcharts" alt="Gem Version" />
|
8
|
+
</a>
|
9
|
+
<a href="https://github.com/styd/apexcharts.rb/actions">
|
10
|
+
<img src="https://github.com/styd/apexcharts.rb/workflows/build-test/badge.svg?branch=master" alt="Build Test Status" />
|
11
|
+
</a>
|
12
|
+
<a href="https://rubygems.org/gems/apexcharts">
|
13
|
+
<img alt="Downloads" src="https://img.shields.io/gem/dt/apexcharts">
|
14
|
+
</a>
|
15
|
+
<img src="https://img.shields.io/github/commit-activity/m/styd/apexcharts.rb.svg?label=commits" alt="Commits" />
|
16
|
+
<a href="https://github.com/styd/apexcharts.rb/blob/master/LICENSE">
|
17
|
+
<img src="https://img.shields.io/badge/License-MIT-brightgreen.svg" alt="License">
|
18
|
+
</a>
|
19
|
+
<a href="https://codeclimate.com/github/styd/apexcharts.rb/maintainability">
|
20
|
+
<img src="https://api.codeclimate.com/v1/badges/07a4f59e67abfeae21cb/maintainability" />
|
21
|
+
</a>
|
22
|
+
<a href="https://codebeat.co/projects/github-com-styd-apexcharts-rb-master">
|
23
|
+
<img alt="codebeat badge" src="https://codebeat.co/badges/7be581d6-e74a-406b-ae76-65605a2bff78" />
|
24
|
+
</a>
|
25
|
+
<a href='https://coveralls.io/github/styd/apexcharts.rb?branch=master'>
|
26
|
+
<img src='https://coveralls.io/repos/github/styd/apexcharts.rb/badge.svg?branch=master' alt='Coverage Status' />
|
27
|
+
</a>
|
28
|
+
<a href='http://clayallsopp.github.io/readme-score/?url=styd/apexcharts.rb'>
|
29
|
+
<img src='http://readme-score-api.herokuapp.com/score.svg?url=styd/apexcharts.rb' alt='README Score' />
|
30
|
+
</a>
|
9
31
|
</p>
|
10
32
|
|
11
33
|
|
12
|
-
##
|
13
|
-
|
14
|
-
ApexCharts.
|
15
|
-
[
|
16
|
-
|
34
|
+
## About
|
35
|
+
|
36
|
+
> ApexCharts.RB is a ruby charting library that's going to give your ruby app beautiful,
|
37
|
+
> interactive, and responsive charts powered by [ApexCharts.JS]. On top of those sweet
|
38
|
+
> advantages, you'll also get extra features that you can't get by just including ApexCharts.JS
|
39
|
+
> to your ruby app, namely **view/template helpers for creating charts**, **options shortcuts**,
|
40
|
+
> **application wide default options**, **reusable custom theme palette**, and so on.
|
41
|
+
|
42
|
+
|
43
|
+
## Trusted By
|
44
|
+
|
45
|
+
Organization/Company | Use Case
|
46
|
+
-----------------------------------------------------------------------|------------------------------------------------------------------
|
47
|
+
<img src="/images/users/copient-health.png" width="143" height="40" /> | Reports/charts related to Operating Room utilization statistics
|
48
|
+
<img src="/images/users/bilendo.png" width="202" height="40" /> | Enterprise dashboards to visualize account receivables data
|
49
|
+
<img src="/images/users/ventrata.png" width="180" height="40" /> | Ticket sales for clients (visitor attractions and tour operators)
|
50
|
+
|
51
|
+
> If your organization/company uses ApexCharts.RB in production, please comment on
|
52
|
+
> [this issue](https://github.com/styd/apexcharts.rb/issues/34).
|
53
|
+
|
54
|
+
|
55
|
+
## Supported By
|
56
|
+
|
57
|
+
<a href="https://www.jetbrains.com/?from=ApexCharts.RB">
|
58
|
+
<img src="images/supporters/jetbrains.svg" title="Grants 1 License for All Products Pack" width="120" height="120" />
|
59
|
+
</a>
|
60
|
+
|
61
|
+
|
62
|
+
## README Versions
|
63
|
+
|
64
|
+
This README might not be for the version you use.
|
65
|
+
Choose the right README:
|
66
|
+
|
67
|
+
> [v0.1.10] | [v0.1.9] | [v0.1.8] | [v0.1.7] | [v0.1.6] | [v0.1.5] | [v0.1.4] | [v0.1.3] | [v0.1.2] | [v0.1.1]
|
68
|
+
|
69
|
+
## Table of Contents
|
70
|
+
|
71
|
+
- [About](#about)
|
72
|
+
- [Trusted By](#trusted-by)
|
73
|
+
- [Supported By](#supported-by)
|
74
|
+
- [README Versions](#readme-versions)
|
75
|
+
- [Table of Contents](#table-of-contents)
|
76
|
+
- [Usage](#usage)
|
77
|
+
- [Cartesian Charts](#cartesian-charts)
|
78
|
+
- [Line Chart](#line-chart)
|
79
|
+
- [Stepline Chart](#stepline-chart)
|
80
|
+
- [Area Chart](#area-chart)
|
81
|
+
- [Column Chart](#column-chart)
|
82
|
+
- [Bar Chart](#bar-chart)
|
83
|
+
- [Range Bar Chart](#range-bar-chart)
|
84
|
+
- [Scatter Chart](#scatter-chart)
|
85
|
+
- [Candlestick Chart](#candlestick-chart)
|
86
|
+
- [Mixed Charts](#mixed-charts)
|
87
|
+
- [Syncing Charts](#syncing-charts)
|
88
|
+
- [Brush Chart](#brush-chart)
|
89
|
+
- [Annotations](#annotations)
|
90
|
+
- [Heatmap Chart](#heatmap-chart)
|
91
|
+
- [Radar Chart](#radar-chart)
|
92
|
+
- [Bubble Chart](#bubble-chart)
|
93
|
+
- [Polar Charts](#polar-charts)
|
94
|
+
- [Pie Chart](#pie-chart)
|
95
|
+
- [Donut Chart](#donut-chart)
|
96
|
+
- [Radial Bar Chart](#radial-bar-chart)
|
97
|
+
- [Data Formats](#data-formats)
|
98
|
+
- [Cartesian Charts](#cartesian-charts-1)
|
99
|
+
- [Candlestick Chart](#candlestick-chart-1)
|
100
|
+
- [Heatmap Chart](#heatmap-chart-1)
|
101
|
+
- [Radar Chart](#radar-chart-1)
|
102
|
+
- [Bubble Chart](#bubble-chart-1)
|
103
|
+
- [Polar Charts](#polar-charts-1)
|
104
|
+
- [Options](#options)
|
105
|
+
- [Global Options](#global-options)
|
106
|
+
- [Formatter Function](#formatter-function)
|
107
|
+
- [Defer Chart Rendering](#defer-chart-rendering)
|
108
|
+
- [Reusable Custom Palette](#reusable-custom-palette)
|
109
|
+
- [Global Palette](#global-palette)
|
110
|
+
- [Local Palette](#local-palette)
|
111
|
+
- [Use Alongside Other Charting Libraries](#use-alongside-other-charting-libraries)
|
112
|
+
- [Alongside Chartkick](#alongside-chartkick)
|
113
|
+
- [Chartkick (Chart.js) and ApexCharts](#chartkick-chartjs-and-apexcharts)
|
114
|
+
- [Chartkick (Google Charts) and ApexCharts](#chartkick-google-charts-and-apexcharts)
|
115
|
+
- [Chartkick (Highcharts) and ApexCharts](#chartkick-highcharts-and-apexcharts)
|
116
|
+
- [Installation](#installation)
|
117
|
+
- [Web Support](#web-support)
|
118
|
+
- [Rails](#rails)
|
119
|
+
- [Sinatra](#sinatra)
|
120
|
+
- [Plain HTML+ERB (Without Framework)](#plain-htmlerb-without-framework)
|
121
|
+
- [Roadmap](#roadmap)
|
122
|
+
- [Contributing](#contributing)
|
123
|
+
- [License](#license)
|
124
|
+
- [Like the charts?](#like-the-charts)
|
17
125
|
|
18
126
|
|
19
127
|
## Usage
|
@@ -101,6 +209,33 @@ Example options used for cartesian charts:
|
|
101
209
|
![Example Bar Chart](images/bar_chart.gif)
|
102
210
|
|
103
211
|
|
212
|
+
#### Range Bar Chart
|
213
|
+
|
214
|
+
```erb
|
215
|
+
<% range_bar_series = [{
|
216
|
+
name: "Series A",
|
217
|
+
data: {
|
218
|
+
'A' => [1, 5],
|
219
|
+
'B' => [4, 6],
|
220
|
+
'C' => [5, 8],
|
221
|
+
'D' => [3, 11]
|
222
|
+
}
|
223
|
+
}, {
|
224
|
+
name: "Series B",
|
225
|
+
data: {
|
226
|
+
'A' => [2, 6],
|
227
|
+
'B' => [1, 3],
|
228
|
+
'C' => [7, 8],
|
229
|
+
'D' => [5, 9]
|
230
|
+
}
|
231
|
+
}]
|
232
|
+
%>
|
233
|
+
|
234
|
+
<%= range_bar_chart(range_bar_series, theme: 'palette3') %>
|
235
|
+
```
|
236
|
+
![Example Range Bar Chart](images/range_bar_chart.gif)
|
237
|
+
|
238
|
+
|
104
239
|
#### Scatter Chart
|
105
240
|
|
106
241
|
```erb
|
@@ -110,6 +245,7 @@ Example options used for cartesian charts:
|
|
110
245
|
|
111
246
|
|
112
247
|
#### Candlestick Chart
|
248
|
+
|
113
249
|
Candlestick chart is typically used to illustrate movements in the price of a
|
114
250
|
financial instrument over time. This chart is also popular by the name "ohlc chart".
|
115
251
|
That's why you can call it with `ohlc_chart` too.
|
@@ -120,13 +256,18 @@ Given:
|
|
120
256
|
<%
|
121
257
|
require 'date'
|
122
258
|
|
123
|
-
def
|
124
|
-
|
259
|
+
def candlestick_data
|
260
|
+
@acc = rand(6570..6650)
|
261
|
+
60.times.map {|i| [Date.today - 60 + i, ohlc] }.to_h
|
125
262
|
end
|
126
263
|
|
127
|
-
|
128
|
-
|
129
|
-
|
264
|
+
def ohlc
|
265
|
+
open = @acc + rand(-20..20)
|
266
|
+
high = open + rand(0..100)
|
267
|
+
low = open - rand(0..100)
|
268
|
+
@acc = close = open + rand(-((high-low)/3)..((high-low)/2))
|
269
|
+
[open, high, low, close]
|
270
|
+
end
|
130
271
|
|
131
272
|
candlestick_options = {
|
132
273
|
plot_options: {
|
@@ -146,9 +287,6 @@ You can make candlestick chart with this:
|
|
146
287
|
```
|
147
288
|
![Example Candlestick Chart](images/candlestick_chart.gif)
|
148
289
|
|
149
|
-
Real life candlestick chart probably don't look like that.
|
150
|
-
That's because I just use random sets of numbers as the data.
|
151
|
-
|
152
290
|
|
153
291
|
#### Mixed Charts
|
154
292
|
|
@@ -176,7 +314,8 @@ you can do this:
|
|
176
314
|
|
177
315
|
#### Syncing Charts
|
178
316
|
|
179
|
-
You can synchronize charts by using `syncing_charts` or `synchronized_charts` methods. For
|
317
|
+
You can synchronize charts by using `syncing_charts` or `synchronized_charts` methods. For
|
318
|
+
example:
|
180
319
|
```erb
|
181
320
|
<%= syncing_charts(chart: {toolbar: false}, height: 250, style: 'display: inline-block; width: 32%;') do %>
|
182
321
|
<% mixed_charts(theme: 'palette4', data_labels: false) do %>
|
@@ -309,6 +448,7 @@ Also called `circle_chart`.
|
|
309
448
|
## Data Formats
|
310
449
|
|
311
450
|
### Cartesian Charts
|
451
|
+
|
312
452
|
The data format for line, stepline, area, column, bar, and scatter
|
313
453
|
charts should be in following format **per-series**:
|
314
454
|
|
@@ -331,6 +471,7 @@ or this:
|
|
331
471
|
```
|
332
472
|
|
333
473
|
#### Candlestick Chart
|
474
|
+
|
334
475
|
Candlestick chart is just like other cartesian charts, only the y value is
|
335
476
|
an array of 4 members which called the OHLC (Open-High-Low-Close):
|
336
477
|
|
@@ -353,6 +494,7 @@ or this:
|
|
353
494
|
```
|
354
495
|
|
355
496
|
### Heatmap Chart
|
497
|
+
|
356
498
|
The data format for heatmap chart **per-series** is similar to cartesian
|
357
499
|
charts. But instead of y values they are heat values. The series names will
|
358
500
|
be the y values.
|
@@ -376,6 +518,7 @@ or this:
|
|
376
518
|
```
|
377
519
|
|
378
520
|
### Radar Chart
|
521
|
+
|
379
522
|
The data format for radar chart **per-series** is also similar but instead
|
380
523
|
of x values they are variables and instead of y values they are the only
|
381
524
|
values for the variables with type of Numeric.
|
@@ -400,6 +543,7 @@ or this:
|
|
400
543
|
|
401
544
|
|
402
545
|
### Bubble Chart
|
546
|
+
|
403
547
|
Bubble chart is similar to scatter chart, only they have one more value
|
404
548
|
for bubble size:
|
405
549
|
|
@@ -412,10 +556,220 @@ for bubble size:
|
|
412
556
|
```
|
413
557
|
|
414
558
|
### Polar Charts
|
559
|
+
|
415
560
|
The data format for donut, pie, and radial bar are the simplest. They are
|
416
561
|
just any single value of type Numeric.
|
417
562
|
|
418
563
|
|
564
|
+
## Options
|
565
|
+
|
566
|
+
ApexCharts.RB supports [all options from ApexCharts.JS](https://apexcharts.com/docs/options/),
|
567
|
+
but instead of *camelCase*, you can write them in *snake_case*.
|
568
|
+
|
569
|
+
ApexCharts.RB also provides shortcuts to some ApexCharts.JS options, such as `title`. In
|
570
|
+
ApexCharts.JS you would have to write
|
571
|
+
|
572
|
+
```ruby
|
573
|
+
title: { text: "Some title" }
|
574
|
+
```
|
575
|
+
In ApexCharts.RB you can write
|
576
|
+
```ruby
|
577
|
+
title: "Some title"
|
578
|
+
```
|
579
|
+
if you just want to add the text.
|
580
|
+
|
581
|
+
`xtitle` and `ytitle` are even greater shortcuts. Instead of
|
582
|
+
```ruby
|
583
|
+
xaxis: { title: { text: "x title" } }
|
584
|
+
```
|
585
|
+
you can write
|
586
|
+
```ruby
|
587
|
+
xtitle: "x title"
|
588
|
+
```
|
589
|
+
|
590
|
+
```ruby
|
591
|
+
options = {
|
592
|
+
animations: false, # Shortcut for chart: { animations: { enabled: false } }
|
593
|
+
chart: {
|
594
|
+
fontFamily: "Helvetica, Arial, sans-serif",
|
595
|
+
toolbar: {
|
596
|
+
show: false
|
597
|
+
}
|
598
|
+
},
|
599
|
+
curve: "straight", # Shortcut for stroke: { curve: "straight" }
|
600
|
+
markers: {
|
601
|
+
size: 5,
|
602
|
+
},
|
603
|
+
tooltip: false, # Shortcut for tooltip: { enabled: false }
|
604
|
+
xtitle: "Boars per capita"
|
605
|
+
}
|
606
|
+
```
|
607
|
+
|
608
|
+
These options can be passed to any chart helper like `<%= line_chart(series, options) %>`.
|
609
|
+
|
610
|
+
### Global Options
|
611
|
+
|
612
|
+
To use default options globally, you can specify config for default options before calling
|
613
|
+
your charts. In Rails, put it in `initializers` directory. For example:
|
614
|
+
|
615
|
+
```ruby
|
616
|
+
# config/initializers/apexcharts.rb
|
617
|
+
|
618
|
+
ApexCharts.config.default_options = {
|
619
|
+
data_labels: false,
|
620
|
+
tootip: true,
|
621
|
+
theme: 'my-theme'
|
622
|
+
}
|
623
|
+
```
|
624
|
+
|
625
|
+
All charts will then automatically pick up these global options, which can be overwritten
|
626
|
+
individually by any options passed to the relevant chart helper.
|
627
|
+
|
628
|
+
### Formatter Function
|
629
|
+
|
630
|
+
To use a _simple_ formatter function (e.g. formatter in `tooltip`, `data_labels`, and `labels`),
|
631
|
+
you can add [functionable-json](https://github.com/styd/functionable-json) to your Gemfile and
|
632
|
+
use it like so:
|
633
|
+
|
634
|
+
```erb
|
635
|
+
<%= area_chart series, tooltip: {y: {formatter: function(val) { return '$' + parseFloat(val).toLocaleString() }}} %>
|
636
|
+
```
|
637
|
+
|
638
|
+
Or, without the _functionable-json_ gem, use function as object as follows:
|
639
|
+
|
640
|
+
```erb
|
641
|
+
<%= area_chart series, tooltip: {y: {formatter: {function: {args: "val", body: "return '$' + parseFloat(val).toLocaleString();"}} }} %>
|
642
|
+
```
|
643
|
+
|
644
|
+
|
645
|
+
### Defer Chart Rendering
|
646
|
+
|
647
|
+
It's possible to defer chart rendering by passing the argument `defer: true` as options.
|
648
|
+
|
649
|
+
```erb
|
650
|
+
<%= line_chart series, defer: true %>
|
651
|
+
```
|
652
|
+
|
653
|
+
|
654
|
+
## Reusable Custom Palette
|
655
|
+
|
656
|
+
You can create custom palette that works globally or locally.
|
657
|
+
|
658
|
+
### Global Palette
|
659
|
+
|
660
|
+
To create global palettes to be used anywhere on your any parts of your app, you can use
|
661
|
+
`ApexCharts::Theme.create`.
|
662
|
+
|
663
|
+
For example, in rails app, you would write it in initializers:
|
664
|
+
|
665
|
+
```ruby
|
666
|
+
# config/initializers/apexcharts.rb
|
667
|
+
ApexCharts::Theme.create "rainbow", ["#ff0000", "#00ff00", "#0000ff"]
|
668
|
+
```
|
669
|
+
|
670
|
+
and later somewhere in your app views:
|
671
|
+
|
672
|
+
```ruby
|
673
|
+
# e.g. app/views/home/index.html.slim
|
674
|
+
...
|
675
|
+
= line_chart chart_data, theme: "rainbow"
|
676
|
+
...
|
677
|
+
```
|
678
|
+
|
679
|
+
If later for some reason I don't know you want to destroy the palette you can use:
|
680
|
+
|
681
|
+
```ruby
|
682
|
+
ApexCharts::Theme.destroy "rainbow"
|
683
|
+
```
|
684
|
+
|
685
|
+
|
686
|
+
## Use Alongside Other Charting Libraries
|
687
|
+
|
688
|
+
You can prefix the helper methods name with your chosen words to avoid name clashing with
|
689
|
+
other charting libraries (e.g. chartkick, google_charts, etc.) you already use. Just set
|
690
|
+
the `APEXCHARTS_PREFIX` environment variable to a string before you start your app server,
|
691
|
+
say, 'awesome\_' and then on your views/templates use the chart helpers as `awesome_line_chart`,
|
692
|
+
`awesome_area_chart`, and so on. `create_palette` and `destroy_palette` are left as is (not
|
693
|
+
prefixed) as other libraries don't seem to have anything similar to them.
|
694
|
+
|
695
|
+
Besides setting the environtment variable, if you just want a quick prefix, you can instead
|
696
|
+
do this on your _Gemfile_:
|
697
|
+
|
698
|
+
```ruby
|
699
|
+
gem 'apexcharts', require: 'apex_charts/prefix_with_apex'
|
700
|
+
```
|
701
|
+
|
702
|
+
and you'll get `apex_line_chart`, `apex_area_chart`, etc.
|
703
|
+
|
704
|
+
The prefix you set only applies to the outer chart helpers. The inner chart helpers is not
|
705
|
+
prefixed. For example:
|
706
|
+
|
707
|
+
```erb
|
708
|
+
<%= awesome_syncing_chart(syncing_options) do %>
|
709
|
+
<% combo_chart(mixed_options) do %>
|
710
|
+
<% line_chart(line_series) %>
|
711
|
+
<% area_chart(area_series) %>
|
712
|
+
<% end %>
|
713
|
+
<% end %>
|
714
|
+
```
|
715
|
+
|
716
|
+
### Alongside Chartkick
|
717
|
+
|
718
|
+
Given:
|
719
|
+
|
720
|
+
```erb
|
721
|
+
<% series = [
|
722
|
+
{name: 'Verified', data: @verified_users},
|
723
|
+
{name: 'Unverified', data: @unverified_users}
|
724
|
+
] %>
|
725
|
+
<% options = {
|
726
|
+
legend: 'bottom', title: 'Users Grouped By Week For The Last 1 Year',
|
727
|
+
ytitle: 'Users', width: '100%', height: '300px'
|
728
|
+
} %>
|
729
|
+
```
|
730
|
+
|
731
|
+
#### Chartkick (Chart.js) and ApexCharts
|
732
|
+
|
733
|
+
```erb
|
734
|
+
<div style="display: inline-block; width: 48%;">
|
735
|
+
<%= area_chart(series, {**options, adapter: 'chartjs'}) %>
|
736
|
+
</div>
|
737
|
+
<div style="display: inline-block; width: 48%;">
|
738
|
+
<%= apex_area_chart(series, options) %>
|
739
|
+
</div>
|
740
|
+
```
|
741
|
+
|
742
|
+
![Chartkick (Chart.js) And ApexCharts](images/chartkick-chartjs-and-apexcharts.gif)
|
743
|
+
|
744
|
+
#### Chartkick (Google Charts) and ApexCharts
|
745
|
+
|
746
|
+
```erb
|
747
|
+
<div style="display: inline-block; width: 48%;">
|
748
|
+
<%= area_chart(series, {**options, adapter: 'google'}) %>
|
749
|
+
</div>
|
750
|
+
|
751
|
+
<div style="display: inline-block; width: 48%;">
|
752
|
+
<%= apex_area_chart(series, options) %>
|
753
|
+
</div>
|
754
|
+
```
|
755
|
+
|
756
|
+
![Chartkick (Google Charts) And ApexCharts](images/chartkick-google-and-apexcharts.gif)
|
757
|
+
|
758
|
+
#### Chartkick (Highcharts) and ApexCharts
|
759
|
+
|
760
|
+
```erb
|
761
|
+
<div style="display: inline-block; width: 48%;">
|
762
|
+
<%= area_chart(series, {**options, adapter: 'highcharts'}) %>
|
763
|
+
</div>
|
764
|
+
|
765
|
+
<div style="display: inline-block; width: 48%;">
|
766
|
+
<%= apex_area_chart(series, options) %>
|
767
|
+
</div>
|
768
|
+
```
|
769
|
+
|
770
|
+
![Chartkick (Highcharts) And ApexCharts](images/chartkick-highcharts-and-apexcharts.gif)
|
771
|
+
|
772
|
+
|
419
773
|
## Installation
|
420
774
|
Add this line to your application's Gemfile:
|
421
775
|
|
@@ -433,53 +787,117 @@ $ bundle
|
|
433
787
|
## Web Support
|
434
788
|
|
435
789
|
### Rails
|
436
|
-
|
790
|
+
|
791
|
+
Require it in your `app/assets/javascripts/application.js`.
|
437
792
|
```js
|
438
|
-
//= require
|
793
|
+
//= require apexcharts
|
439
794
|
```
|
440
795
|
|
441
796
|
Or, if you use `webpacker`, you can run:
|
442
797
|
```bash
|
443
|
-
yarn add apexcharts
|
798
|
+
$ yarn add apexcharts
|
444
799
|
```
|
445
800
|
and then require it in your `app/javascript/packs/application.js`.
|
446
801
|
```js
|
447
|
-
|
802
|
+
// AMD
|
803
|
+
window.ApexCharts = require("apexcharts") // expose to window
|
804
|
+
|
805
|
+
// or
|
806
|
+
// ES6
|
807
|
+
import ApexCharts from 'apexcharts'
|
808
|
+
window.ApexCharts = ApexCharts
|
448
809
|
```
|
449
810
|
|
450
|
-
###
|
451
|
-
|
811
|
+
### Sinatra
|
812
|
+
|
813
|
+
Require it after you `require 'sinatra/base'` and add helper `Sinatra::ApexCharts` in the
|
814
|
+
class that inherits from `Sinatra::Base`.
|
815
|
+
|
816
|
+
```ruby
|
817
|
+
require 'sinatra/base'
|
818
|
+
require 'apexcharts'
|
452
819
|
|
453
|
-
|
820
|
+
class SimpleApp < Sinatra::Base
|
821
|
+
helpers Sinatra::ApexCharts
|
822
|
+
end
|
823
|
+
```
|
824
|
+
|
825
|
+
To add the asset (ApexCharts.JS), include a script tag in your template
|
826
|
+
as follows:
|
827
|
+
|
828
|
+
```ruby
|
829
|
+
template :index do
|
830
|
+
<<~INDEX
|
831
|
+
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
|
832
|
+
<% series = {...} %>
|
833
|
+
<%= pie_chart(series, legend: "left") %>
|
834
|
+
INDEX
|
835
|
+
end
|
836
|
+
```
|
837
|
+
|
838
|
+
For more details, [see example](examples/sinatra/sample.rb).
|
839
|
+
|
840
|
+
|
841
|
+
### Plain HTML+ERB (Without Framework)
|
842
|
+
|
843
|
+
Insert this to the top of your .html.erb files:
|
844
|
+
|
845
|
+
```erb
|
454
846
|
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
|
455
847
|
<% require 'apexcharts' %>
|
848
|
+
<% include ApexCharts::Helper %>
|
849
|
+
```
|
850
|
+
|
851
|
+
You can then generate the static html page with e.g.
|
852
|
+
|
853
|
+
```bash
|
854
|
+
$ erb sample.html.erb > sample.html
|
456
855
|
```
|
457
856
|
|
458
857
|
|
459
|
-
##
|
460
|
-
|
461
|
-
-
|
462
|
-
-
|
463
|
-
-
|
464
|
-
-
|
858
|
+
## Roadmap
|
859
|
+
|
860
|
+
- Support other ruby frameworks (hanami, roda, cuba, middleman, etc.)
|
861
|
+
- v0.1.x
|
862
|
+
- Add more features (e.g. gradient line, background image, etc.)
|
863
|
+
- v0.2.x
|
864
|
+
- Replace dependency `smart_kv` with `dry-schema`
|
865
|
+
- Display warnings on browser console on development instead of error page when
|
866
|
+
schema doesn't meet
|
465
867
|
|
466
868
|
|
467
869
|
## Contributing
|
870
|
+
|
468
871
|
Everyone is encouraged to help improve this project by:
|
469
872
|
- Reporting bugs
|
470
873
|
- Fixing bugs and submiting pull requests
|
471
874
|
- Fixing documentation
|
472
875
|
- Suggesting new features
|
473
|
-
- Implementing
|
876
|
+
- Implementing todos on Roadmap above
|
474
877
|
|
475
878
|
|
476
879
|
## License
|
477
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
478
880
|
|
881
|
+
The gem is available as open source under the terms of the
|
882
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
883
|
+
|
884
|
+
|
885
|
+
## Articles
|
886
|
+
|
887
|
+
- [Rails em 8 minutos: Criando gráficos incríveis com ApexCharts](https://onebitcode.com/graficos-incriveis-no-ruby-on-rails/)
|
888
|
+
- [【Rails】 5分でApexChart.jsを導入する方法](https://qiita.com/syukan3/items/aa741df278f628087a3c)
|
889
|
+
|
890
|
+
|
891
|
+
[ApexCharts.JS]: https://github.com/apexcharts/apexcharts.js
|
479
892
|
|
480
|
-
## Like the charts?
|
481
|
-
Consider donating to the author of apexcharts.js to support his awesome library.
|
482
|
-
This project wouldn't be possible without it.
|
483
893
|
|
484
|
-
|
485
|
-
|
894
|
+
[v0.1.10]: https://github.com/styd/apexcharts.rb/blob/v0.1.10/README.md
|
895
|
+
[v0.1.9]: https://github.com/styd/apexcharts.rb/blob/v0.1.9/README.md
|
896
|
+
[v0.1.8]: https://github.com/styd/apexcharts.rb/blob/v0.1.8/README.md
|
897
|
+
[v0.1.7]: https://github.com/styd/apexcharts.rb/blob/v0.1.7/README.md
|
898
|
+
[v0.1.6]: https://github.com/styd/apexcharts.rb/blob/v0.1.6/README.md
|
899
|
+
[v0.1.5]: https://github.com/styd/apexcharts.rb/blob/v0.1.5/README.md
|
900
|
+
[v0.1.4]: https://github.com/styd/apexcharts.rb/blob/v0.1.4/README.md
|
901
|
+
[v0.1.3]: https://github.com/styd/apexcharts.rb/blob/v0.1.3/README.md
|
902
|
+
[v0.1.2]: https://github.com/styd/apexcharts.rb/blob/v0.1.2/README.md
|
903
|
+
[v0.1.1]: https://github.com/styd/apexcharts.rb/blob/v0.1.1/README.md
|