Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e11c5ca375 | ||
|
|
0af61a2997 | ||
|
|
cb3e4180a1 | ||
|
|
1e7ac1bffb |
@@ -22,6 +22,11 @@
|
|||||||
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
||||||
const data = component.get('areaChartModel.data');
|
const data = component.get('areaChartModel.data');
|
||||||
|
|
||||||
|
const categories = component.get('areaChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('areaChartModel.xAxis.categories')
|
||||||
|
: data.map(item => item.title)
|
||||||
|
;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
series: [{
|
series: [{
|
||||||
name: title,
|
name: title,
|
||||||
@@ -66,7 +71,10 @@
|
|||||||
|
|
||||||
labels: data.map(item => item.title),
|
labels: data.map(item => item.title),
|
||||||
|
|
||||||
xaxis: component.get('areaChartModel.xAxis') || {},
|
xaxis: {
|
||||||
|
labels: component.get('areaChartModel.xAxis.labels'),
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
yaxis: component.get('areaChartModel.yAxis') || {},
|
yaxis: component.get('areaChartModel.yAxis') || {},
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,9 @@
|
|||||||
data: data.map(item => item.value),
|
data: data.map(item => item.value),
|
||||||
}]
|
}]
|
||||||
|
|
||||||
const categories = data.map(item => item.title)
|
const categories = component.get('lineChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('lineChartModel.xAxis.categories')
|
||||||
|
: data.map(item => item.title)
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: series,
|
series: series,
|
||||||
@@ -65,7 +67,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
xaxis: {
|
xaxis: {
|
||||||
...component.get('lineChartModel.xAxis') || {},
|
labels: component.get('lineChartModel.xAxis.labels'),
|
||||||
categories: categories,
|
categories: categories,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
91
resources/views/livewire-multi-column-chart.blade.php
Normal file
91
resources/views/livewire-multi-column-chart.blade.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<div
|
||||||
|
class="w-full h-full"
|
||||||
|
x-data="{ ...multiColumnChart() }"
|
||||||
|
x-init="drawChart(@this)"
|
||||||
|
x-on:draw-column-chart.window="drawChart(@this)"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function multiColumnChart() {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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%',
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -28,7 +28,9 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const categories = []
|
const categories = component.get('lineChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('lineChartModel.xAxis.categories')
|
||||||
|
: data[series[0].name].map(item => item.title)
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: series,
|
series: series,
|
||||||
@@ -51,8 +53,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const seriesName = Object.keys(data)[Object.keys(data).findIndex((el, index) => index === seriesIndex)]
|
const point = data[series[seriesIndex].name][dataPointIndex]
|
||||||
const point = data[seriesName][dataPointIndex]
|
|
||||||
component.call('onPointClick', point)
|
component.call('onPointClick', point)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +69,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
xaxis: {
|
xaxis: {
|
||||||
...component.get('lineChartModel.xAxis') || {},
|
labels: component.get('lineChartModel.xAxis.labels'),
|
||||||
categories: categories,
|
categories: categories,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
/**
|
/**
|
||||||
* Class ColumnChartModel
|
* Class ColumnChartModel
|
||||||
* @package Asantibanez\LivewireCharts\Models
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
* @property boolean $isMultiColumn
|
||||||
*/
|
*/
|
||||||
class ColumnChartModel extends BaseChartModel
|
class ColumnChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $opacity;
|
public $opacity;
|
||||||
|
|
||||||
|
public $isMultiColumn;
|
||||||
|
|
||||||
public $onColumnClickEventName;
|
public $onColumnClickEventName;
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
@@ -23,9 +26,25 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
|
|
||||||
$this->opacity = 0.5;
|
$this->opacity = 0.5;
|
||||||
|
|
||||||
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function multiColumn()
|
||||||
|
{
|
||||||
|
$this->isMultiColumn = true;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function singleColumn()
|
||||||
|
{
|
||||||
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setOpacity($opacity)
|
public function setOpacity($opacity)
|
||||||
{
|
{
|
||||||
$this->opacity = $opacity;
|
$this->opacity = $opacity;
|
||||||
@@ -52,11 +71,28 @@ 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(), [
|
||||||
'onColumnClickEventName' => $this->onColumnClickEventName,
|
'onColumnClickEventName' => $this->onColumnClickEventName,
|
||||||
'opacity' => $this->opacity,
|
'opacity' => $this->opacity,
|
||||||
|
'isMultiColumn' => $this->isMultiColumn,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -69,6 +105,8 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
|
|
||||||
$this->opacity = data_get($array, 'opacity', 0.5);
|
$this->opacity = data_get($array, 'opacity', 0.5);
|
||||||
|
|
||||||
|
$this->isMultiColumn = data_get($array, 'isMultiColumn', false);
|
||||||
|
|
||||||
$this->data = collect(data_get($array, 'data', []));
|
$this->data = collect(data_get($array, 'data', []));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user