Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 457ec73

Browse files
committed
update barchart and docs
Signed-off-by: Dieter Coopman <dieter@deltasolutions.be>
1 parent 744ee3c commit 457ec73

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ composer require lloadout/components
1515
## Dependencies
1616

1717
- [Blade Ui Kit](https://github.com/blade-ui-kit)
18+
- [Apex charts](https://apexcharts.com/)
19+
- [Select 2](https://select2.org/)
1820

1921
## Extra LLoadout components
2022

@@ -27,7 +29,6 @@ The components provide by LLoadout are prefixed with 'load'.
2729

2830
### Select
2931

30-
3132
@php($options = [1 => 'first', 2 => 'second']);
3233
<x-load-select name="your-option" :options="$options" ></x-select>
3334

@@ -41,15 +42,32 @@ This markup will render as
4142
</select>
4243

4344

44-
You can pass in any iterable keyed by a key value pair
45+
You can pass in any iterable keyed by a key value pair. If you add a class 'searchable' , the select field changes into a searchable select2 field.
4546

4647
### Graphs
4748

48-
The charts components make use of apexcharts. Only three types of graphs are implemented in lloadout for now.
49+
The charts components make use of apexcharts. Only three types of graphs are implemented in lloadout for now.
50+
I only created a basic implementation, if you want to add more power to the graphics I refer to Apex Charts itself.
51+
52+
All charts have three params
53+
54+
* title : the title for the graph
55+
* data : an array of data
56+
* labels : an array of labels
57+
58+
The bar chart has an extra param
59+
* orientation : this can be 'horizontal' or 'vertical'
4960

5061
#### Barchart
5162

52-
<x-load-barchart title="Provide a title" key="delayed-{{ now() }}" orientation='horizontal' :data="[['data' => [10,20,70]]]" :labels="['a']"></x-load-barchart>
63+
<x-load-barchart title="Provide a title" key="delayed-{{ now() }}" orientation='horizontal' :data="[10,20,70]" :labels="['a']"></x-load-barchart>
64+
65+
#### Stacked barchart
66+
67+
For the stacked barchart you can use the same tag as for the simple barchart , it takes an array of arrays as data
68+
69+
<x-load-barchart title="Provide a title" key="delayed-{{ now() }}" orientation='horizontal' :data="[[10,20,70],[10,20,70],[10,20,70]]" :labels="['a']"></x-load-barchart>
70+
5371

5472
#### Piechart
5573

resources/assets/js/charts.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function drawBarChart(labels, data, orientation, title, id) {
3232
toolbar: {
3333
export: {
3434
csv: {
35-
filename: title + ".csv",
35+
filename: title,
3636
columnDelimiter: ';',
3737
headerCategory: 'category',
3838
headerValue: 'value',
@@ -41,10 +41,10 @@ function drawBarChart(labels, data, orientation, title, id) {
4141
}
4242
},
4343
svg: {
44-
filename: title + ".svg",
44+
filename: title,
4545
},
4646
png: {
47-
filename: title + ".png",
47+
filename: title,
4848
}
4949
},
5050
}

src/Http/Livewire/BarChart.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BarChart extends Component
1414

1515
public function mount($data = [], $labels = [], $orientation = 'vertical', $title = '')
1616
{
17-
$this->data = $data;
17+
$this->data = $this->transformData($data);
1818
$this->labels = $labels;
1919
$this->orientation = ($orientation == 'vertical') ? false : true;
2020
$this->title = $title;
@@ -28,4 +28,17 @@ public function render()
2828
}
2929
return view('load::livewire.charts.barchart');
3030
}
31+
32+
private function transformData(array $data)
33+
{
34+
if(is_array($data[0])){
35+
return collect($data)->map(function($set){
36+
return ['data' => $set];
37+
})->toArray();
38+
}else{
39+
return [['data' => $data]];
40+
}
41+
42+
43+
}
3144
}

0 commit comments

Comments
 (0)