Skip to content

Commit 67e36b2

Browse files
authored
Add Vue usage
1 parent ffaf4de commit 67e36b2

File tree

1 file changed

+62
-5
lines changed

1 file changed

+62
-5
lines changed

README.md

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ You can change the chart settings of your app from `config/apexcharts.php` file
3535

3636
## Usage
3737

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.
3941

4042
```php
4143
use Akaunting\Apexcharts\Chart;
4244

43-
...
45+
// ...
4446

4547
$chart = (new Chart)->setType('donut')
4648
->setWidth('100%')
@@ -52,11 +54,10 @@ $chart = (new Chart)->setType('donut')
5254
Then, include the JavaScript (on every page using charts).
5355

5456
```html
55-
...
57+
<!-- layout.blade.php -->
5658

57-
</head>
5859
<body>
59-
...
60+
<!-- ... -->
6061

6162
@apexchartsScripts
6263
</body>
@@ -65,11 +66,67 @@ Then, include the JavaScript (on every page using charts).
6566
Finally, call the `container` and `script` method wherever you want to display the chart.
6667

6768
```php
69+
<!-- dashboard.blade.php -->
70+
6871
{!! $chart->container() !!}
6972

7073
{!! $chart->script() !!}
7174
```
7275

76+
### Vue
77+
78+
If you're using Vue and Inertia, create a simple `chart.vue` component:
79+
80+
```vue
81+
<!-- chart.vue -->
82+
83+
<template>
84+
<apexchart
85+
:type="chart.type"
86+
:width="chart.width"
87+
:height="chart.height"
88+
:series="chart.series"
89+
:options="chart.options"
90+
/>
91+
</template>
92+
93+
<script setup>
94+
defineProps({
95+
chart: Object,
96+
});
97+
</script>
98+
```
99+
100+
Then, create an instance of `Chart` and call `toVue()` when passing it to your page:
101+
102+
```php
103+
Route::get('dashboard', function () {
104+
$chart = (new Chart)->setType('...');
105+
106+
return inertia('dashboard', [
107+
'chart' => $chart->toVue(),
108+
]);
109+
});
110+
```
111+
112+
Finally, render the chart:
113+
114+
```vue
115+
<!-- dashboard.vue -->
116+
117+
<template>
118+
<Chart :chart="chart" />
119+
</template>
120+
121+
<script setup>
122+
import Chart from './components/chart.vue';
123+
124+
defineProps({
125+
chart: Object,
126+
});
127+
</script>
128+
```
129+
73130
## Testing
74131

75132
```bash

0 commit comments

Comments
 (0)