Extracted multi line chart Blade view
This commit is contained in:
@@ -21,28 +21,12 @@
|
|||||||
const data = component.get('lineChartModel.data');
|
const data = component.get('lineChartModel.data');
|
||||||
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||||
|
|
||||||
let series = []
|
const series = [{
|
||||||
let categories = []
|
name: title,
|
||||||
|
data: data.map(item => item.value),
|
||||||
|
}]
|
||||||
|
|
||||||
if (isMultiLine) {
|
const categories = data.map(item => item.title)
|
||||||
series = Object.keys(data).map(key => {
|
|
||||||
return {
|
|
||||||
name: key,
|
|
||||||
data: data[key].map(item => item.value),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
categories = []
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isMultiLine) {
|
|
||||||
series = [{
|
|
||||||
name: title,
|
|
||||||
data: data.map(item => item.value),
|
|
||||||
}]
|
|
||||||
|
|
||||||
categories = data.map(item => item.title)
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: series,
|
series: series,
|
||||||
@@ -60,15 +44,8 @@
|
|||||||
enabled: animated,
|
enabled: animated,
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
markerClick: function(event, chartContext, { seriesIndex, dataPointIndex }) {
|
markerClick: function(event, chartContext, { dataPointIndex }) {
|
||||||
if (!onPointClickEventName) {
|
if (!onPointClickEventName) {
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMultiLine) {
|
|
||||||
const seriesName = Object.keys(data)[Object.keys(data).findIndex((el, index) => index === seriesIndex)]
|
|
||||||
const point = data[seriesName][dataPointIndex]
|
|
||||||
component.call('onPointClick', point)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
111
resources/views/livewire-multi-line-chart.blade.php
Normal file
111
resources/views/livewire-multi-line-chart.blade.php
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
<div
|
||||||
|
class="w-full h-full"
|
||||||
|
x-data="{ ...multiLineChart() }"
|
||||||
|
x-init="drawChart(@this)"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function 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 isMultiLine = component.get('lineChartModel.isMultiLine')
|
||||||
|
const data = component.get('lineChartModel.data');
|
||||||
|
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||||
|
|
||||||
|
const series = Object.keys(data).map(key => {
|
||||||
|
return {
|
||||||
|
name: key,
|
||||||
|
data: data[key].map(item => item.value),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const categories = []
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'line',
|
||||||
|
height: '100%',
|
||||||
|
zoom: {
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
|
toolbar: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
animations: {
|
||||||
|
enabled: animated,
|
||||||
|
},
|
||||||
|
events: {
|
||||||
|
markerClick: function(event, chartContext, { seriesIndex, dataPointIndex }) {
|
||||||
|
if (!onPointClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const seriesName = Object.keys(data)[Object.keys(data).findIndex((el, index) => index === seriesIndex)]
|
||||||
|
const point = data[seriesName][dataPointIndex]
|
||||||
|
component.call('onPointClick', point)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
stroke: component.get('lineChartModel.stroke') || {},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center'
|
||||||
|
},
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
...component.get('lineChartModel.xAxis') || {},
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user