Skip to content

Commit e44638a

Browse files
author
cihan emre kisakurek
committed
fix
1 parent 727a7c4 commit e44638a

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

resources/views/livewire/linechart.blade.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,15 @@
1616
}
1717
}
1818
var bar_chart_config = {
19-
type: 'bar',
19+
type: String("{!! $chart_type !!}"),
2020
data: {
2121
labels: @json($labels),
2222
datasets: [{
2323
label: String("{!! $title !!}"),
2424
data: @json($data),
25-
backgroundColor: [
26-
'rgba(255, 99, 132, 0.2)',
27-
'rgba(255, 159, 64, 0.2)',
28-
'rgba(255, 205, 86, 0.2)',
29-
'rgba(75, 192, 192, 0.2)',
30-
'rgba(54, 162, 235, 0.2)',
31-
'rgba(153, 102, 255, 0.2)',
32-
'rgba(201, 203, 207, 0.2)'
33-
],
34-
borderColor: [
35-
'rgb(255, 99, 132)',
36-
'rgb(255, 159, 64)',
37-
'rgb(255, 205, 86)',
38-
'rgb(75, 192, 192)',
39-
'rgb(54, 162, 235)',
40-
'rgb(153, 102, 255)',
41-
'rgb(201, 203, 207)'
42-
],
43-
borderWidth: 1
25+
backgroundColor: @json($background_colors),
26+
borderColor: @json($border_colors),
27+
borderWidth: parseFloat("{!! $border_width !!}")
4428
}]
4529
},
4630
options: {
@@ -53,13 +37,14 @@
5337
}
5438
};
5539
56-
var chart = new Chart(document.getElementById('{{!! $chart_id !!}}'), bar_chart_config);
40+
let chart_id = String("{!! $chart_id !!}");
41+
var chart = new Chart(document.getElementById(chart_id), bar_chart_config);
5742
5843
document.addEventListener("DOMContentLoaded", function() {
59-
window.addEventListener('update_chart_data', event => {
60-
var bar_chart = Chart.getChart('{{!! $chart_id !!}}');
44+
window.addEventListener('update_' + chart_id + '_data' , event => {
45+
var bar_chart = Chart.getChart(chart_id);
6146
bar_chart.destroy();
62-
var ctx = document.getElementById('bar_chart').getContext('2d');
47+
var ctx = document.getElementById(chart_id).getContext('2d');
6348
bar_chart = new Chart(ctx, bar_chart_config);
6449
var chart_data = JSON.parse(event.detail.chart_data);
6550
// chart.data.labels = chart_data.labels;

src/LineChart.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,36 @@ class LineChart extends Component {
1212
public $title = 'title';
1313

1414
public $chart_id = 'la-chart-line-chart';
15+
public $chart_type = 'bar';
16+
17+
public $background_colors = [
18+
'rgba(255, 99, 132, 0.2)',
19+
'rgba(255, 159, 64, 0.2)',
20+
'rgba(255, 205, 86, 0.2)',
21+
'rgba(75, 192, 192, 0.2)',
22+
'rgba(54, 162, 235, 0.2)',
23+
'rgba(153, 102, 255, 0.2)',
24+
'rgba(201, 203, 207, 0.2)'
25+
];
26+
27+
public $border_colors = [
28+
'rgb(255, 99, 132)',
29+
'rgb(255, 159, 64)',
30+
'rgb(255, 205, 86)',
31+
'rgb(75, 192, 192)',
32+
'rgb(54, 162, 235)',
33+
'rgb(153, 102, 255)',
34+
'rgb(201, 203, 207)'
35+
];
36+
37+
public $border_width = 1.0;
1538

1639
public function mount() {
1740

1841

1942
}
2043

21-
public function click() {
44+
public function click($id) {
2245
dd($this);
2346
}
2447

0 commit comments

Comments
 (0)