Skip to content

Commit

Permalink
Fix config loading and allow multiple chart types (bar, line, pie, et…
Browse files Browse the repository at this point in the history
…c) on the same page.
  • Loading branch information
Peter Thomson committed Nov 7, 2024
1 parent 6cce96c commit 287fecb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/resources/views/chart-template-livewire.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div>
<div
x-data="chart({ element: @js($element) }, @js($this->{$model}), {{ $options }} )"
x-data="chart({ element: @js($element), type: @js($type) }, @js($this->{$model}), {{ $options }} )"
wire:loading.class="opacity-50"
>
<canvas id="{{ $element }}" width="@js($size['width'])" height="@js($size['height'])" wire:ignore></canvas>
Expand Down Expand Up @@ -75,7 +75,7 @@

@script
<script>
Alpine.data('chart', Alpine.skipDuringClone((dataset, options) => {
Alpine.data('chart', Alpine.skipDuringClone((config, dataset, options) => {
let chart
return {
Expand All @@ -88,12 +88,12 @@
},
initChart() {
const { element } = config
const { element, type } = config
const el = this.$wire.$el.querySelector('canvas#' + element)
const { labels, datasets } = dataset
return new Chart(el, {
type: @js($type),
type: type,
data: {
labels: labels,
datasets: datasets,
Expand Down

0 comments on commit 287fecb

Please sign in to comment.