Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
230b706c63 | ||
|
|
8b0bb9c250 | ||
|
|
3d89d210b5 | ||
|
|
f72c5294d9 | ||
|
|
76b64536d1 | ||
|
|
fd4961d7ae | ||
|
|
c61ca90905 | ||
|
|
67bd18bc48 | ||
|
|
940109ef03 | ||
|
|
0457a9a007 | ||
|
|
2c7317c3b8 | ||
|
|
98df89eca4 | ||
|
|
de8ed5c844 | ||
|
|
81b502fd10 | ||
|
|
01176c001e | ||
|
|
8e9aed484e | ||
|
|
f5b40ec73d | ||
|
|
dbbbf8eca2 | ||
|
|
a002d2f041 | ||
|
|
e11c5ca375 | ||
|
|
0af61a2997 | ||
|
|
cb3e4180a1 | ||
|
|
1e7ac1bffb | ||
|
|
0aedf541a9 | ||
|
|
316bb5a976 | ||
|
|
05c9f5c605 | ||
|
|
63fe7a1533 | ||
|
|
22b72c1980 | ||
|
|
5e7cabfd16 | ||
|
|
71e2168b6c | ||
|
|
9b74d45a86 | ||
|
|
19f3ce70ae | ||
|
|
4c55e19486 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ docs
|
|||||||
vendor
|
vendor
|
||||||
coverage
|
coverage
|
||||||
.DS_STORE
|
.DS_STORE
|
||||||
|
node_modules
|
||||||
|
|||||||
25
CHANGELOG.md
25
CHANGELOG.md
@@ -1,5 +1,30 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.5.2 - 2020-11-09
|
||||||
|
|
||||||
|
- Fixed infinite growing charts
|
||||||
|
|
||||||
|
## 1.5.1 - 2020-11-09
|
||||||
|
|
||||||
|
- Removed unused Alpine directives
|
||||||
|
|
||||||
|
## 1.5.0 - 2020-11-09
|
||||||
|
|
||||||
|
- Added `LivewireCharts` facade to create any chart model
|
||||||
|
- Added `sparklined` Apex Chart feature to all charts (https://apexcharts.com/javascript-chart-demos/sparklines/basic/)
|
||||||
|
|
||||||
|
## 1.4.0 - 2020-11-07
|
||||||
|
|
||||||
|
- Added Multi Column Chart
|
||||||
|
- Added Stacked Multi Column Chart
|
||||||
|
- Added support for custom X Axis categories
|
||||||
|
|
||||||
|
## 1.3.0 - 2020-11-03
|
||||||
|
|
||||||
|
- Added Multi Line Chart
|
||||||
|
- Added Data Labels configuration for all charts
|
||||||
|
- Refactored title and animation to traits
|
||||||
|
|
||||||
## 1.2.0 - 2020-10-25
|
## 1.2.0 - 2020-10-25
|
||||||
|
|
||||||
- Fixed column chart growing infinitely
|
- Fixed column chart growing infinitely
|
||||||
|
|||||||
97
README.md
97
README.md
@@ -1,11 +1,15 @@
|
|||||||
# Livewire Charts
|
[](https://github.com/asantibanez/livewire-charts/releases/)
|
||||||
|
|
||||||
Neat Livewire Charts for your Laravel projects.
|

|
||||||
|
|
||||||
## Preview
|
## Preview
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
https://github.com/asantibanez/livewire-charts-demo
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
You can install the package via composer:
|
You can install the package via composer:
|
||||||
@@ -14,6 +18,10 @@ You can install the package via composer:
|
|||||||
composer require asantibanez/livewire-charts
|
composer require asantibanez/livewire-charts
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Next, you must export the package public scripts. To do this run `php artisan vendor:publish`
|
||||||
|
and export `livewire-charts:public`. This command will export a `vendor/livewire-charts` folder under the
|
||||||
|
`public` directory of your app.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
This package requires the following packages/libraries to work:
|
This package requires the following packages/libraries to work:
|
||||||
@@ -23,14 +31,14 @@ This package requires the following packages/libraries to work:
|
|||||||
|
|
||||||
Please follow each package/library instructions on how to set them properly in your project.
|
Please follow each package/library instructions on how to set them properly in your project.
|
||||||
|
|
||||||
> Note: At the moment, `Apex Charts` is only supported for drawing charts.
|
>Note: At the moment, `Apex Charts` is only supported for drawing charts.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Livewire Charts supports out of the box the following types of charts
|
Livewire Charts supports out of the box the following types of charts
|
||||||
- Line Chart (`LivewireLineChart` component)
|
- Line/Multi Line Chart (`LivewireLineChart` component)
|
||||||
- Pie Chart (`LivewirePieChart` component)
|
- Pie Chart (`LivewirePieChart` component)
|
||||||
- Column Chart (`LivewireColumnChart` component)
|
- Column/Multi Line Chart (`LivewireColumnChart` component)
|
||||||
- Area Chart (`LivewireAreaChart` component)
|
- Area Chart (`LivewireAreaChart` component)
|
||||||
|
|
||||||
Each one comes with its own "model" class that allows you to define the chart's data and render behavior.
|
Each one comes with its own "model" class that allows you to define the chart's data and render behavior.
|
||||||
@@ -50,7 +58,7 @@ $columnChartModel =
|
|||||||
;
|
;
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note: Chart model methods are chainable 💪
|
>Note: Chart model methods are chainable 💪
|
||||||
|
|
||||||
With `$columnChartModel` at hand, we pass it to our `LivewireColumnChart` component in our Blade template.
|
With `$columnChartModel` at hand, we pass it to our `LivewireColumnChart` component in our Blade template.
|
||||||
|
|
||||||
@@ -60,12 +68,32 @@ With `$columnChartModel` at hand, we pass it to our `LivewireColumnChart` compon
|
|||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Next, include the `@livewireChartsScripts` directive next to your other app scripts
|
||||||
|
|
||||||
|
```html
|
||||||
|
<livewire:scripts />
|
||||||
|
@livewireChartsScripts
|
||||||
|
```
|
||||||
|
|
||||||
And that's it! You have a beautiful rendered chart in seconds. 👌
|
And that's it! You have a beautiful rendered chart in seconds. 👌
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
> Note: You can use these charts inside other Livewire components too. Just render them in your Blade template and you
|
>Note: You can use these charts inside other Livewire components too. Just render them in your Blade template and you
|
||||||
are good to go. 👍
|
are good to go. 👍
|
||||||
|
|
||||||
|
## LivewireCharts facade
|
||||||
|
|
||||||
|
Chart models can also be created using the `LivewireCharts` facade.
|
||||||
|
|
||||||
|
```php
|
||||||
|
LivewireCharts::lineChartModel();
|
||||||
|
LivewireCharts::multiLineChartModel();
|
||||||
|
LivewireCharts::columnChartModel();
|
||||||
|
LivewireCharts::multiColumnChartModel();
|
||||||
|
LivewireCharts::pieChartModel();
|
||||||
|
LivewireCharts::areaChartModel();
|
||||||
|
```
|
||||||
|
|
||||||
## Enabling Interactions
|
## Enabling Interactions
|
||||||
|
|
||||||
@@ -125,23 +153,40 @@ The parent component renders the charts as follows
|
|||||||
For each chart, a specific model class needs to be used. Here, it is detailed the api available
|
For each chart, a specific model class needs to be used. Here, it is detailed the api available
|
||||||
for each type of chart.
|
for each type of chart.
|
||||||
|
|
||||||
#### LivewireLineChart
|
#### All
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| setTitle(string $title) | Sets chart title |
|
| setTitle(string $title) | Sets chart title |
|
||||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
| setAnimated(boolean $animated) | Enables/disables animation |
|
||||||
| addPoint(string $title, double $value, array $extras = []) | Adds a point to the line chart. `$extras` is forwarded on click event |
|
| setDataLabelsEnabled(boolean $enabled) | Enables/disables data labels |
|
||||||
| addMarker(string $title, double $value) | Adds a marker point to the line chart. Markers are used to emphasize particular points in the chart |
|
| withDataLabels() | Enables data labels |
|
||||||
|
| withoutDataLabels() | Disables data labels |
|
||||||
|
| withLegend() | Shows legends |
|
||||||
|
| withoutLegend() | Hides legends |
|
||||||
|
| setXAxisCategories(array $categories) | Enables custom categories for chart X Axis |
|
||||||
|
| sparklined() | Enables Apex Charts sparkline feature |
|
||||||
|
| setSparklineEnabled(boolean $isEnabled) | Enables/Disables Apex Charts sparkline feature |
|
||||||
|
|
||||||
|
#### LivewireLineChart
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| multiLine() | Adds multiline support for line chart |
|
||||||
|
| singleLine() | Adds single support for line chart |
|
||||||
|
| addPoint(string $title, double $value, array $extras = []) | Adds a point to a single line chart. `$extras` is forwarded on click event |
|
||||||
|
| addSeriesPoint(string $seriesName, string $title, double $value, array $extras = []) | Adds a point to series to a multi line chart. `$extras` is forwarded on click event |
|
||||||
|
| addMarker(string $title, double $value) | Adds a marker point to the line chart. Markers are used to emphasize particular points in the chart (singleLine only) |
|
||||||
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point/marker of the chart is clicked |
|
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point/marker of the chart is clicked |
|
||||||
|
|
||||||
#### LivewireColumnChart
|
#### LivewireColumnChart
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| setTitle(string $title) | Sets chart title |
|
|
||||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
|
||||||
| setOpacity(int $opacity) | Sets columns' opacity |
|
| setOpacity(int $opacity) | Sets columns' opacity |
|
||||||
|
| multiColumn() | Sets chart to display multiple column series |
|
||||||
|
| singleColumn() | Sets chart to display a single column series |
|
||||||
|
| stacked() | Sets chart to display column series stacked |
|
||||||
| addColumn(string $title, double $value, string $color, array $extras = []) | Adds a column to the chart with the specified color. `$extras` is forwarded on click event |
|
| addColumn(string $title, double $value, string $color, array $extras = []) | Adds a column to the chart with the specified color. `$extras` is forwarded on click event |
|
||||||
| onColumnClickEventName(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
| onColumnClickEventName(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
||||||
|
|
||||||
@@ -149,8 +194,6 @@ for each type of chart.
|
|||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| setTitle(string $title) | Sets chart title |
|
|
||||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
|
||||||
| setOpacity(int $opacity) | Sets slices' opacity |
|
| setOpacity(int $opacity) | Sets slices' opacity |
|
||||||
| addSlice(string $title, double $value, string $color, array $extras = []) | Adds a slice to the chart with the specified color. `$extras` is forwarded on click event |
|
| addSlice(string $title, double $value, string $color, array $extras = []) | Adds a slice to the chart with the specified color. `$extras` is forwarded on click event |
|
||||||
| withOnSliceClickEvent(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
| withOnSliceClickEvent(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
||||||
@@ -159,13 +202,33 @@ for each type of chart.
|
|||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| setTitle(string $title) | Sets chart title |
|
|
||||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
|
||||||
| addPoint(string $title, double $value, array $extras = []) | Adds a point to the area chart. `$extras` is forwarded on click event |
|
| addPoint(string $title, double $value, array $extras = []) | Adds a point to the area chart. `$extras` is forwarded on click event |
|
||||||
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point of the chart is clicked |
|
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point of the chart is clicked |
|
||||||
| setXAxisVisible(boolean $visible) | Shows/hides xAxis labels |
|
| setXAxisVisible(boolean $visible) | Shows/hides xAxis labels |
|
||||||
| setYAxisVisible(boolean $visible) | Shows/hides yAxis labels |
|
| setYAxisVisible(boolean $visible) | Shows/hides yAxis labels |
|
||||||
|
|
||||||
|
## Advanced Usage - Integrating Scripts
|
||||||
|
|
||||||
|
The directive `@livewireChartsScripts` adds a `script` tag that includes `public/vendor/livewire-charts/app.js`.
|
||||||
|
If you want to include this script in your build system, you can export the package scripts
|
||||||
|
with `php artisan vendor:publish` and selecting `livewire-charts:scripts`. This will export `js/vendor/livewire-charts`
|
||||||
|
inside your resources folder. You can then adjust imports as you see fit in your project.
|
||||||
|
|
||||||
|
>Note: You must remove @livewireChartsScripts directive so it doesn't clash with the scripts in your build system.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
Chart components must be placed inside a container with fixed height. This is because the chart will use all the given
|
||||||
|
vertical space. A fixed height is needed to render properly.
|
||||||
|
|
||||||
|
```blade
|
||||||
|
<div style="height: 32rem;">
|
||||||
|
<livewire:livewire-column-chart .../>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
>Note: if a fixed height is not given, the chart will grow vertically infinitely. That's not what we want, right?
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
|
|||||||
3
mix-manifest.json
Normal file
3
mix-manifest.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"/public/app.js": "/public/app.js"
|
||||||
|
}
|
||||||
22043
package-lock.json
generated
Normal file
22043
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
package.json
Normal file
16
package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"dev": "npm run development",
|
||||||
|
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
|
||||||
|
"watch": "npm run development -- --watch",
|
||||||
|
"watch-poll": "npm run watch -- --watch-poll",
|
||||||
|
"prod": "npm run production",
|
||||||
|
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"apexcharts": "^3.22.2",
|
||||||
|
"cross-env": "^7.0.2",
|
||||||
|
"laravel-mix": "^5.0.9",
|
||||||
|
"vue-template-compiler": "^2.6.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
2
public/app.js
Normal file
2
public/app.js
Normal file
File diff suppressed because one or more lines are too long
13
public/app.js.LICENSE.txt
Normal file
13
public/app.js.LICENSE.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/*!
|
||||||
|
* ApexCharts v3.22.2
|
||||||
|
* (c) 2018-2020 Juned Chhipa
|
||||||
|
* Released under the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! svg.draggable.js - v2.2.2 - 2019-01-08
|
||||||
|
* https://github.com/svgdotjs/svg.draggable.js
|
||||||
|
* Copyright (c) 2019 Wout Fierens; Licensed MIT */
|
||||||
|
|
||||||
|
/*! svg.filter.js - v2.0.2 - 2016-02-24
|
||||||
|
* https://github.com/wout/svg.filter.js
|
||||||
|
* Copyright (c) 2016 Wout Fierens; Licensed MIT */
|
||||||
15
resources/js/app.js
Normal file
15
resources/js/app.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import ApexCharts from 'apexcharts'
|
||||||
|
import areaChart from "./areaChart"
|
||||||
|
import columnChart from "./columnChart"
|
||||||
|
import multiColumnChart from "./multiColumnChart";
|
||||||
|
import lineChart from "./lineChart"
|
||||||
|
import multiLineChart from "./multiLineChart"
|
||||||
|
import pieChart from "./pieChart"
|
||||||
|
|
||||||
|
window.ApexCharts = ApexCharts
|
||||||
|
window.livewireChartsAreaChart = areaChart
|
||||||
|
window.livewireChartsColumnChart = columnChart
|
||||||
|
window.livewireChartsLineChart = lineChart
|
||||||
|
window.livewireChartsMultiLineChart = multiLineChart
|
||||||
|
window.livewireChartsPieChart = pieChart
|
||||||
|
window.livewireChartsMultiColumnChart = multiColumnChart
|
||||||
88
resources/js/areaChart.js
Normal file
88
resources/js/areaChart.js
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
|
||||||
|
const areaChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('areaChartModel.title');
|
||||||
|
const animated = component.get('areaChartModel.animated') || false;
|
||||||
|
const dataLabels = component.get('areaChartModel.dataLabels') || {};
|
||||||
|
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
||||||
|
const data = component.get('areaChartModel.data');
|
||||||
|
const sparkline = component.get('areaChartModel.sparkline');
|
||||||
|
|
||||||
|
const categories = component.get('areaChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('areaChartModel.xAxis.categories')
|
||||||
|
: data.map(item => item.title)
|
||||||
|
;
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
series: [{
|
||||||
|
name: title,
|
||||||
|
data: data.map(item => item.value)
|
||||||
|
}],
|
||||||
|
chart: {
|
||||||
|
type: 'area',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
zoom: { enabled: false },
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
markerClick: function(event, chartContext, { dataPointIndex }) {
|
||||||
|
if (!onPointClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const point = data[dataPointIndex]
|
||||||
|
component.call('onPointClick', point)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
colors: [component.get('areaChartModel.color') || '#2E93fA'],
|
||||||
|
|
||||||
|
stroke: component.get('areaChartModel.stroke') || {},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center'
|
||||||
|
},
|
||||||
|
|
||||||
|
labels: data.map(item => item.title),
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
labels: component.get('areaChartModel.xAxis.labels'),
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: component.get('areaChartModel.yAxis') || {},
|
||||||
|
|
||||||
|
grid: {
|
||||||
|
padding: {
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default areaChart
|
||||||
84
resources/js/columnChart.js
Normal file
84
resources/js/columnChart.js
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
|
||||||
|
const columnChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const animated = component.get('columnChartModel.animated') || false;
|
||||||
|
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
||||||
|
const dataLabels = component.get('columnChartModel.dataLabels') || {};
|
||||||
|
const data = component.get('columnChartModel.data');
|
||||||
|
const sparkline = component.get('columnChartModel.sparkline');
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: [{ data: data.map(item => item.value)}],
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'bar',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
dataPointSelection: function(event, chartContext, config) {
|
||||||
|
if (!onColumnClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { dataPointIndex } = config
|
||||||
|
const column = data[dataPointIndex]
|
||||||
|
component.call('onColumnClick', column)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
colors: data.map(item => item.color),
|
||||||
|
|
||||||
|
labels: {
|
||||||
|
style: {
|
||||||
|
colors: data.map(item => item.color),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
legend: component.get('columnChartModel.legend') || {},
|
||||||
|
|
||||||
|
plotOptions: {
|
||||||
|
bar: {
|
||||||
|
horizontal: false,
|
||||||
|
columnWidth: '40%',
|
||||||
|
distributed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
categories: data.map(item => item.title),
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: {
|
||||||
|
title: {
|
||||||
|
text: component.get('columnChartModel.title'),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
fill: {
|
||||||
|
opacity: component.get('columnChartModel.opacity') || 0.5
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default columnChart
|
||||||
102
resources/js/lineChart.js
Normal file
102
resources/js/lineChart.js
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
|
||||||
|
const lineChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('lineChartModel.title');
|
||||||
|
const animated = component.get('lineChartModel.animated') || false;
|
||||||
|
const dataLabels = component.get('lineChartModel.dataLabels') || {};
|
||||||
|
const data = component.get('lineChartModel.data');
|
||||||
|
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||||
|
const sparkline = component.get('lineChartModel.sparkline');
|
||||||
|
|
||||||
|
const series = [{
|
||||||
|
name: title,
|
||||||
|
data: data.map(item => item.value),
|
||||||
|
}]
|
||||||
|
|
||||||
|
const categories = component.get('lineChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('lineChartModel.xAxis.categories')
|
||||||
|
: data.map(item => item.title)
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'line',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
zoom: { enabled: false },
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
markerClick: function(event, chartContext, { dataPointIndex }) {
|
||||||
|
if (!onPointClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const point = data[dataPointIndex]
|
||||||
|
component.call('onPointClick', point)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
stroke: component.get('lineChartModel.stroke') || {},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center'
|
||||||
|
},
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
labels: component.get('lineChartModel.xAxis.labels'),
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: component.get('lineChartModel.yAxis') || {},
|
||||||
|
|
||||||
|
annotations: {
|
||||||
|
points: component.get('lineChartModel.markers').map(item => {
|
||||||
|
return {
|
||||||
|
x: item.title,
|
||||||
|
y: item.value,
|
||||||
|
marker: {
|
||||||
|
size: 6,
|
||||||
|
fillColor: '#fff',
|
||||||
|
strokeColor: item.strokeColor,
|
||||||
|
radius: 2,
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
offsetY: 0,
|
||||||
|
style: {
|
||||||
|
color: item.textColor,
|
||||||
|
background: item.textBackgroundColor,
|
||||||
|
},
|
||||||
|
text: item.text || '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default lineChart
|
||||||
87
resources/js/multiColumnChart.js
Normal file
87
resources/js/multiColumnChart.js
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
|
||||||
|
const multiColumnChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const stacked = component.get('columnChartModel.isStacked');
|
||||||
|
const animated = component.get('columnChartModel.animated');
|
||||||
|
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
||||||
|
const dataLabels = component.get('columnChartModel.dataLabels');
|
||||||
|
const data = component.get('columnChartModel.data');
|
||||||
|
const sparkline = component.get('columnChartModel.sparkline');
|
||||||
|
|
||||||
|
const series = Object.keys(data)
|
||||||
|
.map(seriesName => ({
|
||||||
|
name: seriesName,
|
||||||
|
data: data[seriesName].map(item => item.value)
|
||||||
|
}))
|
||||||
|
|
||||||
|
const categories = component.get('columnChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('columnChartModel.xAxis.categories')
|
||||||
|
: data[series[0].name].map(item => item.title)
|
||||||
|
;
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'bar',
|
||||||
|
height: '100%',
|
||||||
|
stacked: stacked,
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
dataPointSelection: function(event, chartContext, {seriesIndex, dataPointIndex}) {
|
||||||
|
if (!onColumnClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const column = data[series[seriesIndex].name][dataPointIndex]
|
||||||
|
component.call('onColumnClick', column)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
legend: component.get('columnChartModel.legend'),
|
||||||
|
|
||||||
|
plotOptions: {
|
||||||
|
bar: {
|
||||||
|
horizontal: false,
|
||||||
|
columnWidth: '50%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: {
|
||||||
|
title: {
|
||||||
|
text: component.get('columnChartModel.title'),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
fill: {
|
||||||
|
opacity: component.get('columnChartModel.opacity'),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default multiColumnChart
|
||||||
79
resources/js/multiLineChart.js
Normal file
79
resources/js/multiLineChart.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
const multiLineChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('lineChartModel.title');
|
||||||
|
const animated = component.get('lineChartModel.animated') || false;
|
||||||
|
const dataLabels = component.get('lineChartModel.dataLabels') || {};
|
||||||
|
const data = component.get('lineChartModel.data');
|
||||||
|
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||||
|
const sparkline = component.get('lineChartModel.sparkline');
|
||||||
|
|
||||||
|
const series = Object.keys(data).map(key => {
|
||||||
|
return {
|
||||||
|
name: key,
|
||||||
|
data: data[key].map(item => item.value),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const categories = component.get('lineChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('lineChartModel.xAxis.categories')
|
||||||
|
: data[series[0].name].map(item => item.title)
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'line',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
zoom: { enabled: false },
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
markerClick: function(event, chartContext, { seriesIndex, dataPointIndex }) {
|
||||||
|
if (!onPointClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const point = data[series[seriesIndex].name][dataPointIndex]
|
||||||
|
component.call('onPointClick', point)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
stroke: component.get('lineChartModel.stroke') || {},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center'
|
||||||
|
},
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
labels: component.get('lineChartModel.xAxis.labels'),
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: component.get('lineChartModel.yAxis') || {},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default multiLineChart
|
||||||
77
resources/js/pieChart.js
Normal file
77
resources/js/pieChart.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
|
||||||
|
const pieChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('pieChartModel.title');
|
||||||
|
const animated = component.get('pieChartModel.animated') || false
|
||||||
|
const dataLabels = component.get('pieChartModel.dataLabels') || {}
|
||||||
|
const onSliceClickEventName = component.get('pieChartModel.onSliceClickEventName')
|
||||||
|
const data = component.get('pieChartModel.data')
|
||||||
|
const sparkline = component.get('pieChartModel.sparkline')
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: data.map(item => item.value),
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
height: '100%',
|
||||||
|
type: 'pie',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
dataPointSelection: function(event, chartContext, config) {
|
||||||
|
if (!onSliceClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { dataPointIndex } = config
|
||||||
|
const slice = data[dataPointIndex]
|
||||||
|
component.call('onSliceClick', slice)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
labels: data.map(item => item.title),
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
colors: data.map(item => item.color),
|
||||||
|
|
||||||
|
fill: {
|
||||||
|
opacity: component.get('pieChartModel.opacity'),
|
||||||
|
},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
|
||||||
|
responsive: [
|
||||||
|
{
|
||||||
|
breakpoint: 600,
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
position: 'bottom'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
legend: component.get('pieChartModel.legend') || {},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default pieChart
|
||||||
@@ -1,87 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...areaChart() }"
|
x-data="{ ...livewireChartsAreaChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
x-on:draw-column-chart.window="drawChart(@this)"
|
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function areaChart() {
|
|
||||||
return {
|
|
||||||
chart: null,
|
|
||||||
|
|
||||||
drawChart(component) {
|
|
||||||
if (this.chart) {
|
|
||||||
this.chart.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
series: [{
|
|
||||||
name: component.get('areaChartModel.title'),
|
|
||||||
data: component.get('areaChartModel.data').map(item => item.value)
|
|
||||||
}],
|
|
||||||
chart: {
|
|
||||||
type: 'area',
|
|
||||||
height: '100%',
|
|
||||||
|
|
||||||
zoom: { enabled: false },
|
|
||||||
|
|
||||||
toolbar: { show: false },
|
|
||||||
|
|
||||||
animations: {
|
|
||||||
enabled: component.get('areaChartModel.animated') || false,
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
|
||||||
markerClick: function(event, chartContext, { dataPointIndex }) {
|
|
||||||
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
|
||||||
if (!onPointClickEventName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const point = component.get('areaChartModel.data')[dataPointIndex]
|
|
||||||
component.call('onPointClick', point)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false
|
|
||||||
},
|
|
||||||
|
|
||||||
colors: [component.get('areaChartModel.color') || '#2E93fA'],
|
|
||||||
|
|
||||||
stroke: {
|
|
||||||
curve: 'straight'
|
|
||||||
},
|
|
||||||
|
|
||||||
title: {
|
|
||||||
text: component.get('areaChartModel.title'),
|
|
||||||
align: 'center'
|
|
||||||
},
|
|
||||||
|
|
||||||
labels: component.get('areaChartModel.data').map(item => item.title),
|
|
||||||
|
|
||||||
xaxis: component.get('areaChartModel.xAxis') || {},
|
|
||||||
|
|
||||||
yaxis: component.get('areaChartModel.yAxis') || {},
|
|
||||||
|
|
||||||
grid: {
|
|
||||||
padding: {
|
|
||||||
left: 0,
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
|
||||||
this.chart.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,97 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...columnChart() }"
|
x-data="{ ...livewireChartsColumnChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
x-on:draw-column-chart.window="drawChart(@this)"
|
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function columnChart() {
|
|
||||||
return {
|
|
||||||
chart: null,
|
|
||||||
|
|
||||||
drawChart(component) {
|
|
||||||
this.renderApex(component)
|
|
||||||
},
|
|
||||||
|
|
||||||
renderApex(component) {
|
|
||||||
if (this.chart) {
|
|
||||||
this.chart.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
series: [{ data: component.get('columnChartModel.data').map(item => item.value)}],
|
|
||||||
|
|
||||||
chart: {
|
|
||||||
type: 'bar',
|
|
||||||
height: '100%',
|
|
||||||
|
|
||||||
toolbar: {
|
|
||||||
show: false
|
|
||||||
},
|
|
||||||
|
|
||||||
animations: {
|
|
||||||
enabled: component.get('columnChartModel.animated') || false,
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
|
||||||
dataPointSelection: function(event, chartContext, config) {
|
|
||||||
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
|
||||||
|
|
||||||
if (!onColumnClickEventName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const { dataPointIndex } = config
|
|
||||||
const column = component.get('columnChartModel.data')[dataPointIndex]
|
|
||||||
component.call('onColumnClick', column)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
colors: component.get('columnChartModel.data').map(item => item.color),
|
|
||||||
|
|
||||||
labels: {
|
|
||||||
style: {
|
|
||||||
colors: component.get('columnChartModel.data').map(item => item.color),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
legend: component.get('columnChartModel.legend') || {},
|
|
||||||
|
|
||||||
plotOptions: {
|
|
||||||
bar: {
|
|
||||||
horizontal: false,
|
|
||||||
columnWidth: '40%',
|
|
||||||
distributed: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
xaxis: {
|
|
||||||
categories: component.get('columnChartModel.data').map(item => item.title),
|
|
||||||
},
|
|
||||||
|
|
||||||
yaxis: {
|
|
||||||
title: {
|
|
||||||
text: component.get('columnChartModel.title'),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
fill: {
|
|
||||||
opacity: component.get('columnChartModel.opacity') || 0.5
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
|
||||||
this.chart.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,99 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...lineChart() }"
|
x-data="{ ...livewireChartsLineChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function lineChart() {
|
|
||||||
return {
|
|
||||||
chart: null,
|
|
||||||
|
|
||||||
drawChart(component) {
|
|
||||||
if (this.chart) {
|
|
||||||
this.chart.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
series: [{
|
|
||||||
name: component.get('lineChartModel.title'),
|
|
||||||
data: component.get('lineChartModel.data').map(item => item.value),
|
|
||||||
}],
|
|
||||||
|
|
||||||
chart: {
|
|
||||||
type: 'line',
|
|
||||||
height: '100%',
|
|
||||||
zoom: {
|
|
||||||
enabled: false
|
|
||||||
},
|
|
||||||
toolbar: {
|
|
||||||
show: false
|
|
||||||
},
|
|
||||||
animations: {
|
|
||||||
enabled: component.get('lineChartModel.animated') || false,
|
|
||||||
},
|
|
||||||
events: {
|
|
||||||
markerClick: function(event, chartContext, { dataPointIndex }) {
|
|
||||||
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName')
|
|
||||||
if (!onPointClickEventName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const point = component.get('lineChartModel.data')[dataPointIndex]
|
|
||||||
component.call('onPointClick', point)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false
|
|
||||||
},
|
|
||||||
|
|
||||||
stroke: component.get('lineChartModel.stroke') || {},
|
|
||||||
|
|
||||||
title: {
|
|
||||||
text: component.get('lineChartModel.title'),
|
|
||||||
align: 'center'
|
|
||||||
},
|
|
||||||
|
|
||||||
xaxis: {
|
|
||||||
...component.get('lineChartModel.xAxis') || {},
|
|
||||||
categories: component.get('lineChartModel.data').map(item => item.title),
|
|
||||||
},
|
|
||||||
|
|
||||||
yaxis: component.get('lineChartModel.yAxis') || {},
|
|
||||||
|
|
||||||
annotations: {
|
|
||||||
points: component.get('lineChartModel.markers').map(item => {
|
|
||||||
return {
|
|
||||||
x: item.title,
|
|
||||||
y: item.value,
|
|
||||||
marker: {
|
|
||||||
size: 6,
|
|
||||||
fillColor: '#fff',
|
|
||||||
strokeColor: item.strokeColor,
|
|
||||||
radius: 2,
|
|
||||||
},
|
|
||||||
label: {
|
|
||||||
offsetY: 0,
|
|
||||||
style: {
|
|
||||||
color: item.textColor,
|
|
||||||
background: item.textBackgroundColor,
|
|
||||||
},
|
|
||||||
text: item.text || '',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
|
||||||
this.chart.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
8
resources/views/livewire-multi-column-chart.blade.php
Normal file
8
resources/views/livewire-multi-column-chart.blade.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<div
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
x-data="{ ...livewireChartsMultiColumnChart() }"
|
||||||
|
x-init="drawChart(@this)"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
8
resources/views/livewire-multi-line-chart.blade.php
Normal file
8
resources/views/livewire-multi-line-chart.blade.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<div
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
x-data="{ ...livewireChartsMultiLineChart() }"
|
||||||
|
x-init="drawChart(@this)"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -1,82 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...pieChart() }"
|
x-data="{ ...livewireChartsPieChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function pieChart() {
|
|
||||||
return {
|
|
||||||
chart: null,
|
|
||||||
|
|
||||||
drawChart(component) {
|
|
||||||
if (this.chart) {
|
|
||||||
this.chart.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
series: component.get('pieChartModel.data').map(item => item.value),
|
|
||||||
|
|
||||||
chart: {
|
|
||||||
height: '100%',
|
|
||||||
type: 'pie',
|
|
||||||
|
|
||||||
animations: {
|
|
||||||
enabled: component.get('pieChartModel.animated') || false,
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
|
||||||
dataPointSelection: function(event, chartContext, config) {
|
|
||||||
const onSliceClickEventName = component.get('pieChartModel.onSliceClickEventName')
|
|
||||||
|
|
||||||
if (!onSliceClickEventName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const { dataPointIndex } = config
|
|
||||||
const slice = component.get('pieChartModel.data')[dataPointIndex]
|
|
||||||
component.call('onSliceClick', slice)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
labels: component.get('pieChartModel.data').map(item => item.title),
|
|
||||||
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
colors: component.get('pieChartModel.data').map(item => item.color),
|
|
||||||
|
|
||||||
fill: {
|
|
||||||
opacity: component.get('pieChartModel.opacity'),
|
|
||||||
},
|
|
||||||
|
|
||||||
title: {
|
|
||||||
text: component.get('pieChartModel.title'),
|
|
||||||
align: 'center',
|
|
||||||
},
|
|
||||||
|
|
||||||
responsive: [
|
|
||||||
{
|
|
||||||
breakpoint: 600,
|
|
||||||
options: {
|
|
||||||
legend: {
|
|
||||||
position: 'bottom'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
legend: component.get('pieChartModel.legend') || {},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
|
||||||
this.chart.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ class LivewireColumnChart extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
|
if ($this->columnChartModel['isMultiColumn']) {
|
||||||
|
return view('livewire-charts::livewire-multi-column-chart');
|
||||||
|
}
|
||||||
|
|
||||||
return view('livewire-charts::livewire-column-chart');
|
return view('livewire-charts::livewire-column-chart');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ class LivewireLineChart extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
|
if ($this->lineChartModel['isMultiLine']) {
|
||||||
|
return view('livewire-charts::livewire-multi-line-chart');
|
||||||
|
}
|
||||||
|
|
||||||
return view('livewire-charts::livewire-line-chart');
|
return view('livewire-charts::livewire-line-chart');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/Facades/LivewireCharts.php
Normal file
27
src/Facades/LivewireCharts.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Facades;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class LivewireCharts
|
||||||
|
* @package Asantibanez\LivewireCharts\Facades
|
||||||
|
* @method static LineChartModel lineChartModel()
|
||||||
|
* @method static LineChartModel multiLineChartModel()
|
||||||
|
* @method static ColumnChartModel columnChartModel()
|
||||||
|
* @method static ColumnChartModel multiColumnChartModel()
|
||||||
|
* @method static AreaChartModel areaChartModel()
|
||||||
|
* @method static PieChartModel pieChartModel()
|
||||||
|
*/
|
||||||
|
class LivewireCharts extends Facade
|
||||||
|
{
|
||||||
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'livewirecharts';
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/LivewireCharts.php
Normal file
47
src/LivewireCharts.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts;
|
||||||
|
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
||||||
|
|
||||||
|
class LivewireCharts
|
||||||
|
{
|
||||||
|
public function lineChartModel()
|
||||||
|
{
|
||||||
|
return (new LineChartModel)
|
||||||
|
->singleLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function multiLineChartModel()
|
||||||
|
{
|
||||||
|
return (new LineChartModel)
|
||||||
|
->multiLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function columnChartModel()
|
||||||
|
{
|
||||||
|
return (new ColumnChartModel)
|
||||||
|
->singleColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function multiColumnChartModel()
|
||||||
|
{
|
||||||
|
return (new ColumnChartModel)
|
||||||
|
->multiColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function areaChartModel()
|
||||||
|
{
|
||||||
|
return new AreaChartModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pieChartModel()
|
||||||
|
{
|
||||||
|
return new PieChartModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,35 +6,65 @@ use Asantibanez\LivewireCharts\Charts\LivewireAreaChart;
|
|||||||
use Asantibanez\LivewireCharts\Charts\LivewireColumnChart;
|
use Asantibanez\LivewireCharts\Charts\LivewireColumnChart;
|
||||||
use Asantibanez\LivewireCharts\Charts\LivewireLineChart;
|
use Asantibanez\LivewireCharts\Charts\LivewireLineChart;
|
||||||
use Asantibanez\LivewireCharts\Charts\LivewirePieChart;
|
use Asantibanez\LivewireCharts\Charts\LivewirePieChart;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
|
|
||||||
class LivewireChartsServiceProvider extends ServiceProvider
|
class LivewireChartsServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Bootstrap the application services.
|
|
||||||
*/
|
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-charts');
|
$this->registerViews();
|
||||||
|
|
||||||
|
$this->registerPublishables();
|
||||||
|
|
||||||
|
$this->registerComponents();
|
||||||
|
|
||||||
|
$this->registerDirectives();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->bind('livewirecharts', LivewireCharts::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerViews()
|
||||||
|
{
|
||||||
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-charts');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerPublishables()
|
||||||
|
{
|
||||||
if ($this->app->runningInConsole()) {
|
if ($this->app->runningInConsole()) {
|
||||||
$this->publishes([
|
$this->publishes([
|
||||||
__DIR__.'/../resources/views' => resource_path('views/vendor/livewire-charts'),
|
__DIR__.'/../resources/views' => resource_path('views/vendor/livewire-charts'),
|
||||||
], 'livewire-charts-views');
|
], 'livewire-charts:views');
|
||||||
}
|
|
||||||
|
|
||||||
|
$this->publishes([
|
||||||
|
__DIR__.'/../resources/js' => resource_path('js/vendor/livewire-charts'),
|
||||||
|
], 'livewire-charts:scripts');
|
||||||
|
|
||||||
|
$this->publishes([
|
||||||
|
__DIR__.'/../public' => public_path('vendor/livewire-charts'),
|
||||||
|
], 'livewire-charts:public');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerComponents()
|
||||||
|
{
|
||||||
Livewire::component('livewire-line-chart', LivewireLineChart::class);
|
Livewire::component('livewire-line-chart', LivewireLineChart::class);
|
||||||
Livewire::component('livewire-column-chart', LivewireColumnChart::class);
|
Livewire::component('livewire-column-chart', LivewireColumnChart::class);
|
||||||
Livewire::component('livewire-pie-chart', LivewirePieChart::class);
|
Livewire::component('livewire-pie-chart', LivewirePieChart::class);
|
||||||
Livewire::component('livewire-area-chart', LivewireAreaChart::class);
|
Livewire::component('livewire-area-chart', LivewireAreaChart::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function registerDirectives()
|
||||||
* Register the application services.
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
{
|
||||||
//
|
Blade::directive('livewireChartsScripts', function () {
|
||||||
|
$scriptsUrl = asset('/vendor/livewire-charts/app.js');
|
||||||
|
return <<<EOF
|
||||||
|
<script src="$scriptsUrl"></script>
|
||||||
|
EOF;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
*/
|
*/
|
||||||
class AreaChartModel extends BaseChartModel
|
class AreaChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $title;
|
|
||||||
|
|
||||||
public $animated;
|
|
||||||
|
|
||||||
public $color;
|
public $color;
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
@@ -23,10 +19,6 @@ class AreaChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->title = '';
|
|
||||||
|
|
||||||
$this->animated = false;
|
|
||||||
|
|
||||||
$this->color = '#90cdf4';
|
$this->color = '#90cdf4';
|
||||||
|
|
||||||
$this->onPointClickEventName = null;
|
$this->onPointClickEventName = null;
|
||||||
@@ -34,20 +26,6 @@ class AreaChartModel extends BaseChartModel
|
|||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle($title)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAnimated($animated)
|
|
||||||
{
|
|
||||||
$this->animated = $animated;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setColor($color)
|
public function setColor($color)
|
||||||
{
|
{
|
||||||
$this->color = $color;
|
$this->color = $color;
|
||||||
@@ -76,8 +54,6 @@ class AreaChartModel extends BaseChartModel
|
|||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array_merge(parent::toArray(), [
|
return array_merge(parent::toArray(), [
|
||||||
'title' => $this->title,
|
|
||||||
'animated' => $this->animated,
|
|
||||||
'color' => $this->color,
|
'color' => $this->color,
|
||||||
'onPointClickEventName' => $this->onPointClickEventName,
|
'onPointClickEventName' => $this->onPointClickEventName,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
@@ -88,10 +64,6 @@ class AreaChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::fromArray($array);
|
parent::fromArray($array);
|
||||||
|
|
||||||
$this->title = data_get($array, 'title', '');
|
|
||||||
|
|
||||||
$this->animated = data_get($array, 'animated', false);
|
|
||||||
|
|
||||||
$this->color = data_get($array, 'color', '#90cdf4');
|
$this->color = data_get($array, 'color', '#90cdf4');
|
||||||
|
|
||||||
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
||||||
|
|||||||
@@ -9,15 +9,23 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
*/
|
*/
|
||||||
class BaseChartModel
|
class BaseChartModel
|
||||||
{
|
{
|
||||||
|
use HasTitle;
|
||||||
|
use HasAnimation;
|
||||||
use HasAxis;
|
use HasAxis;
|
||||||
use HasStroke;
|
use HasStroke;
|
||||||
use HasLegend;
|
use HasLegend;
|
||||||
|
use HasDataLabels;
|
||||||
|
use HasSparkline;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->initTitle();
|
||||||
|
$this->initAnimation();
|
||||||
$this->initAxis();
|
$this->initAxis();
|
||||||
$this->initStroke();
|
$this->initStroke();
|
||||||
$this->initLegend();
|
$this->initLegend();
|
||||||
|
$this->initDataLabels();
|
||||||
|
$this->initSparkline();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reactiveKey()
|
public function reactiveKey()
|
||||||
@@ -28,16 +36,24 @@ class BaseChartModel
|
|||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array_merge(
|
return array_merge(
|
||||||
|
$this->titleToArray(),
|
||||||
|
$this->animationToArray(),
|
||||||
$this->axisToArray(),
|
$this->axisToArray(),
|
||||||
$this->strokeToArray(),
|
$this->strokeToArray(),
|
||||||
$this->legendToArray()
|
$this->legendToArray(),
|
||||||
|
$this->dataLabelsToArray(),
|
||||||
|
$this->sparklineToArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromArray($array)
|
public function fromArray($array)
|
||||||
{
|
{
|
||||||
|
$this->titleFromArray($array);
|
||||||
|
$this->animationFromArray($array);
|
||||||
$this->axisFromArray($array);
|
$this->axisFromArray($array);
|
||||||
$this->strokeFromArray($array);
|
$this->strokeFromArray($array);
|
||||||
$this->legendFromArray($array);
|
$this->legendFromArray($array);
|
||||||
|
$this->dataLabelsFromArray($array);
|
||||||
|
$this->sparklineFromArray($array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,17 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
/**
|
/**
|
||||||
* Class ColumnChartModel
|
* Class ColumnChartModel
|
||||||
* @package Asantibanez\LivewireCharts\Models
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
* @property boolean $isMultiColumn
|
||||||
|
* @property boolean $isStacked
|
||||||
*/
|
*/
|
||||||
class ColumnChartModel extends BaseChartModel
|
class ColumnChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $title;
|
|
||||||
|
|
||||||
public $animated;
|
|
||||||
|
|
||||||
public $opacity;
|
public $opacity;
|
||||||
|
|
||||||
|
public $isMultiColumn;
|
||||||
|
|
||||||
|
public $isStacked;
|
||||||
|
|
||||||
public $onColumnClickEventName;
|
public $onColumnClickEventName;
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
@@ -23,27 +25,34 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->title = '';
|
|
||||||
|
|
||||||
$this->animated = false;
|
|
||||||
|
|
||||||
$this->onColumnClickEventName = null;
|
$this->onColumnClickEventName = null;
|
||||||
|
|
||||||
$this->opacity = 0.5;
|
$this->opacity = 0.5;
|
||||||
|
|
||||||
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
|
$this->isStacked = false;
|
||||||
|
|
||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle($title)
|
public function multiColumn()
|
||||||
{
|
{
|
||||||
$this->title = $title;
|
$this->isMultiColumn = true;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAnimated($animated)
|
public function singleColumn()
|
||||||
{
|
{
|
||||||
$this->animated = $animated;
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stacked()
|
||||||
|
{
|
||||||
|
$this->isStacked = true;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -74,13 +83,29 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addSeriesColumn($seriesName, $title, $value, $extras = [])
|
||||||
|
{
|
||||||
|
$series = $this->data->get($seriesName, collect());
|
||||||
|
|
||||||
|
$series->push([
|
||||||
|
'seriesName' => $seriesName,
|
||||||
|
'title' => $title,
|
||||||
|
'value' => $value,
|
||||||
|
'extras' => $extras,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->data->put($seriesName, $series);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array_merge(parent::toArray(), [
|
return array_merge(parent::toArray(), [
|
||||||
'title' => $this->title,
|
|
||||||
'animated' => $this->animated,
|
|
||||||
'onColumnClickEventName' => $this->onColumnClickEventName,
|
'onColumnClickEventName' => $this->onColumnClickEventName,
|
||||||
'opacity' => $this->opacity,
|
'opacity' => $this->opacity,
|
||||||
|
'isMultiColumn' => $this->isMultiColumn,
|
||||||
|
'isStacked' => $this->isStacked,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -89,14 +114,14 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::fromArray($array);
|
parent::fromArray($array);
|
||||||
|
|
||||||
$this->title = data_get($array, 'title', '');
|
|
||||||
|
|
||||||
$this->animated = data_get($array, 'animated', false);
|
|
||||||
|
|
||||||
$this->onColumnClickEventName = data_get($array, 'onColumnClickEventName', null);
|
$this->onColumnClickEventName = data_get($array, 'onColumnClickEventName', null);
|
||||||
|
|
||||||
$this->opacity = data_get($array, 'opacity', 0.5);
|
$this->opacity = data_get($array, 'opacity', 0.5);
|
||||||
|
|
||||||
|
$this->isMultiColumn = data_get($array, 'isMultiColumn', false);
|
||||||
|
|
||||||
|
$this->isStacked = data_get($array, 'isStacked', false);
|
||||||
|
|
||||||
$this->data = collect(data_get($array, 'data', []));
|
$this->data = collect(data_get($array, 'data', []));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
src/Models/HasAnimation.php
Normal file
39
src/Models/HasAnimation.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasAnimation
|
||||||
|
{
|
||||||
|
private $animated;
|
||||||
|
|
||||||
|
public function setAnimated($animated)
|
||||||
|
{
|
||||||
|
$this->animated = $animated;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initAnimation()
|
||||||
|
{
|
||||||
|
$this->animated = $this->defaultAnimated();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultAnimated()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function animationFromArray($array)
|
||||||
|
{
|
||||||
|
$this->animated = data_get($array, 'animated', $this->defaultAnimated());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function animationToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'animated' => $this->animated,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ trait HasAxis
|
|||||||
|
|
||||||
private $yAxis;
|
private $yAxis;
|
||||||
|
|
||||||
public function initAxis()
|
protected function initAxis()
|
||||||
{
|
{
|
||||||
$this->xAxis = $this->defaultXAxis();
|
$this->xAxis = $this->defaultXAxis();
|
||||||
$this->yAxis = $this->defaultYAxis();
|
$this->yAxis = $this->defaultYAxis();
|
||||||
@@ -19,6 +19,7 @@ trait HasAxis
|
|||||||
private function defaultXAxis()
|
private function defaultXAxis()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'categories' => [],
|
||||||
'labels' => [
|
'labels' => [
|
||||||
'show' => true,
|
'show' => true,
|
||||||
],
|
],
|
||||||
@@ -39,6 +40,13 @@ trait HasAxis
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setXAxisCategories($categories = [])
|
||||||
|
{
|
||||||
|
data_set($this->xAxis, 'categories', $categories);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setYAxisVisible($visible)
|
public function setYAxisVisible($visible)
|
||||||
{
|
{
|
||||||
data_set($this->yAxis, 'show', $visible);
|
data_set($this->yAxis, 'show', $visible);
|
||||||
|
|||||||
55
src/Models/HasDataLabels.php
Normal file
55
src/Models/HasDataLabels.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasDataLabels
|
||||||
|
{
|
||||||
|
private $dataLabels;
|
||||||
|
|
||||||
|
public function setDataLabelsEnabled($enabled)
|
||||||
|
{
|
||||||
|
data_set($this->dataLabels, 'enabled', $enabled);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withDataLabels()
|
||||||
|
{
|
||||||
|
data_set($this->dataLabels, 'enabled', true);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withoutDataLabels()
|
||||||
|
{
|
||||||
|
data_set($this->dataLabels, 'enabled', false);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initDataLabels()
|
||||||
|
{
|
||||||
|
$this->dataLabels = $this->defaultDataLabels();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultDataLabels()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'enabled' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function dataLabelsFromArray($array)
|
||||||
|
{
|
||||||
|
$this->dataLabels = data_get($array, 'dataLabels', $this->defaultDataLabels());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function dataLabelsToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'dataLabels' => $this->dataLabels,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/Models/HasSparkline.php
Normal file
48
src/Models/HasSparkline.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasSparkline
|
||||||
|
{
|
||||||
|
private $sparkline;
|
||||||
|
|
||||||
|
public function setSparklineEnabled($isEnabled)
|
||||||
|
{
|
||||||
|
data_set($this->sparkline, 'sparkline.enabled', $isEnabled);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sparklined()
|
||||||
|
{
|
||||||
|
return $this->setSparklineEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initSparkline()
|
||||||
|
{
|
||||||
|
$this->sparkline = $this->defaultSparkline();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultSparkline()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'sparkline' => [
|
||||||
|
'enabled' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function sparklineFromArray($array)
|
||||||
|
{
|
||||||
|
$this->sparkline = data_get($array, 'sparkline', $this->defaultSparkline());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function sparklineToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'sparkline' => $this->sparkline,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
trait HasStroke
|
trait HasStroke
|
||||||
{
|
{
|
||||||
private $stroke;
|
private $stroke;
|
||||||
|
private $width;
|
||||||
|
|
||||||
public function initStroke()
|
public function initStroke()
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,7 @@ trait HasStroke
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'curve' => 'straight',
|
'curve' => 'straight',
|
||||||
|
'width' => 4
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +36,13 @@ trait HasStroke
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setStrokeWidth($width)
|
||||||
|
{
|
||||||
|
data_set($this->stroke, 'width', $width);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function strokeToArray()
|
protected function strokeToArray()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
39
src/Models/HasTitle.php
Normal file
39
src/Models/HasTitle.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasTitle
|
||||||
|
{
|
||||||
|
private $title;
|
||||||
|
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initTitle()
|
||||||
|
{
|
||||||
|
$this->title = $this->defaultTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultTitle()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function titleFromArray($array)
|
||||||
|
{
|
||||||
|
$this->title = data_get($array, 'title', $this->defaultTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function titleToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => $this->title,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,15 +3,16 @@
|
|||||||
|
|
||||||
namespace Asantibanez\LivewireCharts\Models;
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LineChartModel
|
* Class LineChartModel
|
||||||
* @package Asantibanez\LivewireCharts\Models
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
* @property boolean $isMultiLine
|
||||||
*/
|
*/
|
||||||
class LineChartModel extends BaseChartModel
|
class LineChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $title;
|
public $isMultiLine;
|
||||||
|
|
||||||
public $animated;
|
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
|
|
||||||
@@ -23,9 +24,7 @@ class LineChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->title = '';
|
$this->isMultiLine = false;
|
||||||
|
|
||||||
$this->animated = false;
|
|
||||||
|
|
||||||
$this->onPointClickEventName = null;
|
$this->onPointClickEventName = null;
|
||||||
|
|
||||||
@@ -34,16 +33,20 @@ class LineChartModel extends BaseChartModel
|
|||||||
$this->markers = collect();
|
$this->markers = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle($title)
|
public function multiLine()
|
||||||
{
|
{
|
||||||
$this->title = $title;
|
$this->isMultiLine = true;
|
||||||
|
|
||||||
|
$this->data = collect();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAnimated($animated)
|
public function singleLine()
|
||||||
{
|
{
|
||||||
$this->animated = $animated;
|
$this->isMultiLine = false;
|
||||||
|
|
||||||
|
$this->data = collect();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -59,6 +62,22 @@ class LineChartModel extends BaseChartModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addSeriesPoint($seriesName, $title, $value, $extras = [])
|
||||||
|
{
|
||||||
|
$series = $this->data->get($seriesName, collect());
|
||||||
|
|
||||||
|
$series->push([
|
||||||
|
'seriesName' => $seriesName,
|
||||||
|
'title' => $title,
|
||||||
|
'value' => $value,
|
||||||
|
'extras' => $extras,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->data->put($seriesName, $series);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function addMarker($title,
|
public function addMarker($title,
|
||||||
$value,
|
$value,
|
||||||
$strokeColor = 'green',
|
$strokeColor = 'green',
|
||||||
@@ -88,8 +107,7 @@ class LineChartModel extends BaseChartModel
|
|||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array_merge(parent::toArray(), [
|
return array_merge(parent::toArray(), [
|
||||||
'title' => $this->title,
|
'isMultiLine' => $this->isMultiLine,
|
||||||
'animated' => $this->animated,
|
|
||||||
'onPointClickEventName' => $this->onPointClickEventName,
|
'onPointClickEventName' => $this->onPointClickEventName,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
'markers' => $this->markers->toArray(),
|
'markers' => $this->markers->toArray(),
|
||||||
@@ -100,9 +118,7 @@ class LineChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::fromArray($array);
|
parent::fromArray($array);
|
||||||
|
|
||||||
$this->title = data_get($array, 'title', '');
|
$this->isMultiLine = data_get($array, 'isMultiLine', false);
|
||||||
|
|
||||||
$this->animated = data_get($array, 'animated', false);
|
|
||||||
|
|
||||||
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
*/
|
*/
|
||||||
class PieChartModel extends BaseChartModel
|
class PieChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $title;
|
|
||||||
|
|
||||||
public $animated;
|
|
||||||
|
|
||||||
public $onSliceClickEventName;
|
public $onSliceClickEventName;
|
||||||
|
|
||||||
public $opacity;
|
public $opacity;
|
||||||
@@ -23,10 +19,6 @@ class PieChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->title = '';
|
|
||||||
|
|
||||||
$this->animated = false;
|
|
||||||
|
|
||||||
$this->onSliceClickEventName = null;
|
$this->onSliceClickEventName = null;
|
||||||
|
|
||||||
$this->opacity = 0.75;
|
$this->opacity = 0.75;
|
||||||
@@ -34,20 +26,6 @@ class PieChartModel extends BaseChartModel
|
|||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle($title)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAnimated($animated)
|
|
||||||
{
|
|
||||||
$this->animated = $animated;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setOpacity($opacity)
|
public function setOpacity($opacity)
|
||||||
{
|
{
|
||||||
$this->opacity = $opacity;
|
$this->opacity = $opacity;
|
||||||
@@ -77,8 +55,6 @@ class PieChartModel extends BaseChartModel
|
|||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array_merge(parent::toArray(), [
|
return array_merge(parent::toArray(), [
|
||||||
'title' => $this->title,
|
|
||||||
'animated' => $this->animated,
|
|
||||||
'onSliceClickEventName' => $this->onSliceClickEventName,
|
'onSliceClickEventName' => $this->onSliceClickEventName,
|
||||||
'opacity' => $this->opacity,
|
'opacity' => $this->opacity,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
@@ -89,10 +65,6 @@ class PieChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::fromArray($array);
|
parent::fromArray($array);
|
||||||
|
|
||||||
$this->title = data_get($array, 'title', '');
|
|
||||||
|
|
||||||
$this->animated = data_get($array, 'animated', false);
|
|
||||||
|
|
||||||
$this->onSliceClickEventName = data_get($array, 'onSliceClickEventName', null);
|
$this->onSliceClickEventName = data_get($array, 'onSliceClickEventName', null);
|
||||||
|
|
||||||
$this->opacity = data_get($array, 'opacity', 0.75);
|
$this->opacity = data_get($array, 'opacity', 0.75);
|
||||||
|
|||||||
3
webpack.mix.js
Normal file
3
webpack.mix.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
let mix = require('laravel-mix')
|
||||||
|
|
||||||
|
mix.js('resources/js/app.js', 'public/')
|
||||||
Reference in New Issue
Block a user