@@ -35,12 +35,14 @@ You can change the chart settings of your app from `config/apexcharts.php` file
35
35
36
36
## Usage
37
37
38
- First of all, create an instance of the ` Chart ` class and set the data and options according to your needs.
38
+ ### Blade
39
+
40
+ Create an instance of the ` Chart ` class and set the data and options according to your needs.
39
41
40
42
``` php
41
43
use Akaunting\Apexcharts\Chart;
42
44
43
- ...
45
+ // ...
44
46
45
47
$chart = (new Chart)->setType('donut')
46
48
->setWidth('100%')
@@ -52,11 +54,10 @@ $chart = (new Chart)->setType('donut')
52
54
Then, include the JavaScript (on every page using charts).
53
55
54
56
``` html
55
- ...
57
+ <!-- layout.blade.php -->
56
58
57
- </head >
58
59
<body >
59
- ...
60
+ <!-- ... -->
60
61
61
62
@apexchartsScripts
62
63
</body >
@@ -65,11 +66,89 @@ Then, include the JavaScript (on every page using charts).
65
66
Finally, call the ` container ` and ` script ` method wherever you want to display the chart.
66
67
67
68
``` php
69
+ <!-- dashboard.blade.php -->
70
+
68
71
{!! $chart->container() !!}
69
72
70
73
{!! $chart->script() !!}
71
74
```
72
75
76
+ ### Vue
77
+
78
+ If you're using Vue and Inertia, install Apexcharts and their Vue 3 adapter:
79
+
80
+ ``` bash
81
+ npm install --save apexcharts
82
+ npm install --save vue3-apexcharts
83
+ ```
84
+
85
+ ``` js
86
+ // resources/js/app.js
87
+
88
+ import VueApexCharts from ' vue3-apexcharts' ;
89
+
90
+ createInertiaApp ({
91
+ // ...
92
+ setup ({el, App, props, plugin}) {
93
+ return createApp ({ render : () => h (App, props) })
94
+ .use (VueApexCharts)
95
+ .mount (el);
96
+ },
97
+ });
98
+ ```
99
+
100
+ Then, create a simple ` chart.vue ` component:
101
+
102
+ ``` vue
103
+ <!-- components/chart.vue -->
104
+
105
+ <template>
106
+ <apexchart
107
+ :type="chart.type"
108
+ :width="chart.width"
109
+ :height="chart.height"
110
+ :series="chart.series"
111
+ :options="chart.options"
112
+ />
113
+ </template>
114
+
115
+ <script setup>
116
+ defineProps({
117
+ chart: Object,
118
+ });
119
+ </script>
120
+ ```
121
+
122
+ Create an instance of ` Chart ` and call ` toVue() ` before passing it to your page:
123
+
124
+ ``` php
125
+ Route::get('dashboard', function () {
126
+ $chart = (new Chart)->setType('...');
127
+
128
+ return inertia('dashboard', [
129
+ 'chart' => $chart->toVue(),
130
+ ]);
131
+ });
132
+ ```
133
+
134
+ Finally, render the chart:
135
+
136
+ ``` vue
137
+ <!-- pages/dashboard.vue -->
138
+
139
+ <template>
140
+ <Chart :chart="chart" />
141
+ </template>
142
+
143
+ <script setup>
144
+ import Chart from './components/chart.vue';
145
+
146
+ defineProps({
147
+ chart: Object,
148
+ });
149
+ </script>
150
+ ```
151
+
73
152
## Testing
74
153
75
154
``` bash
0 commit comments