Flux's Chart component is a lightweight, zero-dependency tool for building charts in your Livewire applications. It is designed to be simple but extremely flexible, so that you can assemble and style your charts exactly as you need them.
Currently, Flux supports line and area charts. Additional chart types are planned for future releases.
<flux:chart wire:model="data" class="aspect-3/1"> <flux:chart.svg> <flux:chart.line field="visitors" class="text-pink-500 dark:text-pink-400" /> <flux:chart.axis axis="x" field="date"> <flux:chart.axis.line /> <flux:chart.axis.tick /> </flux:chart.axis> <flux:chart.axis axis="y"> <flux:chart.axis.grid /> <flux:chart.axis.tick /> </flux:chart.axis> <flux:chart.cursor /> </flux:chart.svg> <flux:chart.tooltip> <flux:chart.tooltip.heading field="date" :format="['year' => 'numeric', 'month' => 'numeric', 'day' => 'numeric']" /> <flux:chart.tooltip.value field="visitors" label="Visitors" /> </flux:chart.tooltip></flux:chart>
<?phpuse Livewire\Component;class Dashboard extends Component{ public array $data = [ ['date' => '2025-03-26', 'visitors' => 267], ['date' => '2025-03-25', 'visitors' => 259], ['date' => '2025-03-24', 'visitors' => 269], // ... ];}
<flux:chart wire:model="data" />
<flux:chart :value="$this->data" />
<flux:chart :value="[1, 2, 3, 4, 5]" />
<flux:chart wire:model="data" class="aspect-[3/1]"> <flux:chart.svg> <flux:chart.line field="memory" class="text-pink-500" /> <flux:chart.point field="memory" class="text-pink-400" /> <flux:chart.axis axis="x" field="date"> <flux:chart.axis.tick /> <flux:chart.axis.line /> </flux:chart.axis> <flux:chart.axis axis="y" tick-values="[0, 128, 256, 384, 512]" :format="['style' => 'unit', 'unit' => 'megabyte']"> <flux:chart.axis.grid /> <flux:chart.axis.tick /> </flux:chart.axis> </flux:chart.svg></flux:chart>
<flux:chart wire:model="data" class="aspect-3/1"> <flux:chart.svg> <flux:chart.line field="stock" class="text-blue-500 dark:text-blue-400" curve="none" /> <flux:chart.area field="stock" class="text-blue-200/50 dark:text-blue-400/30" curve="none" /> <flux:chart.axis axis="y" position="right" tick-prefix="$" :format="[ 'notation' => 'compact', 'compactDisplay' => 'short', 'maximumFractionDigits' => 1, ]"> <flux:chart.axis.grid /> <flux:chart.axis.tick /> </flux:chart.axis> <flux:chart.axis axis="x" field="date"> <flux:chart.axis.tick /> <flux:chart.axis.line /> </flux:chart.axis> </flux:chart.svg></flux:chart>
<flux:chart wire:model="data"> <flux:chart.viewport class="min-h-[20rem]" > <flux:chart.svg> <flux:chart.line field="twitter" class="text-blue-500" curve="none" /> <flux:chart.point field="twitter" class="text-blue-500" r="6" stroke-width="3" /> <flux:chart.line field="facebook" class="text-red-500" curve="none" /> <flux:chart.point field="facebook" class="text-red-500" r="6" stroke-width="3" /> <flux:chart.line field="instagram" class="text-green-500" curve="none" /> <flux:chart.point field="instagram" class="text-green-500" r="6" stroke-width="3" /> <flux:chart.axis axis="x" field="date"> <flux:chart.axis.tick /> <flux:chart.axis.line /> </flux:chart.axis> <flux:chart.axis axis="y" tick-start="0" tick-end="1" :format="[ 'style' => 'percent', 'minimumFractionDigits' => 0, 'maximumFractionDigits' => 0, ]"> <flux:chart.axis.grid /> <flux:chart.axis.tick /> </flux:chart.axis> </flux:chart.svg> </flux:chart.viewport> <div class="flex justify-center gap-4 pt-4"> <flux:chart.legend label="Instagram"> <flux:chart.legend.indicator class="bg-green-400" /> </flux:chart.legend> <flux:chart.legend label="Twitter"> <flux:chart.legend.indicator class="bg-blue-400" /> </flux:chart.legend> <flux:chart.legend label="Facebook"> <flux:chart.legend.indicator class="bg-red-400" /> </flux:chart.legend> </div></flux:chart>
<flux:card> <flux:chart class="grid gap-6" wire:model="data"> <flux:chart.summary class="flex gap-12"> <div> <flux:text>Today</flux:text> <flux:heading size="xl" class="mt-2 tabular-nums"> <flux:chart.summary.value field="sales" :format="['style' => 'currency', 'currency' => 'USD']" /> </flux:heading> <flux:text class="mt-2 tabular-nums"> <flux:chart.summary.value field="date" :format="['hour' => 'numeric', 'minute' => 'numeric', 'hour12' => true]" /> </flux:text> </div> <div> <flux:text>Yesterday</flux:text> <flux:heading size="lg" class="mt-2 tabular-nums"> <flux:chart.summary.value field="yesterday" :format="['style' => 'currency', 'currency' => 'USD']" /> </flux:heading> </div> </flux:chart.summary> <flux:chart.viewport class="aspect-[3/1]"> <flux:chart.svg> <flux:chart.line field="yesterday" class="text-zinc-300 dark:text-white/40" stroke-dasharray="4 4" curve="none" /> <flux:chart.line field="sales" class="text-sky-500 dark:text-sky-400" curve="none" /> <flux:chart.axis axis="x" field="date"> <flux:chart.axis.grid /> <flux:chart.axis.tick /> <flux:chart.axis.line /> </flux:chart.axis> <flux:chart.axis axis="y"> <flux:chart.axis.tick /> </flux:chart.axis> <flux:chart.cursor /> </flux:chart.svg> </flux:chart.viewport> </flux:chart></flux:card>
Stock
|
Price
|
Change
|
Trend
|
---|---|---|---|
AAPL | $193.45 |
|
|
MSFT | $338.12 |
|
|
TSLA | $242.68 |
|
|
GOOGL | $129.87 |
|
<flux:chart :value="[15, 18, 16, 19, 22, 25, 28, 25, 29, 28, 32, 35]" class="w-[5rem] aspect-[3/1]"> <flux:chart.svg gutter="0"> <flux:chart.line class="text-green-500 dark:text-green-400" /> </flux:chart.svg></flux:chart>
<flux:card class="overflow-hidden min-w-[12rem]"> <flux:text>Revenue</flux:text> <flux:heading size="xl" class="mt-2 tabular-nums">$12,345</flux:heading> <flux:chart class="-mx-8 -mb-8 h-[3rem]" :value="[10, 12, 11, 13, 15, 14, 16, 18, 17, 19, 21, 20]"> <flux:chart.svg gutter="0"> <flux:chart.line class="text-sky-200 dark:text-sky-400" /> <flux:chart.area class="text-sky-100 dark:text-sky-400/30" /> </flux:chart.svg> </flux:chart></flux:card>
<flux:chart> <flux:chart.svg gutter="12 0 12 8"> <!-- ... --> </flux:chart.svg></flux:chart>
<flux:chart.axis axis="y" scale="linear"> <!-- ... --></flux:chart.axis>
<flux:chart.svg> <!-- ... --> <flux:chart.axis axis="x"> <!-- Horizontal "X" axis line: --> <flux:chart.axis.line /> </flux:chart.axis> <flux:chart.axis axis="y"> <!-- Vertical "Y" axis line: --> <flux:chart.axis.line /> </flux:chart.axis></flux:chart.svg>
<!-- A dark gray axis line that is 2px wide and has a gray color: --><flux:chart.axis.line class="text-zinc-800" stroke-width="2" />
<flux:chart.svg> <!-- ... --> <!-- Zero line: --> <flux:chart.zero-line /></flux:chart.svg>
<!-- A dark gray zero line that is 2px wide and has a gray color: --><flux:chart.zero-line class="text-zinc-800" stroke-width="2" />
<flux:chart.svg> <!-- ... --> <flux:chart.axis axis="x"> <!-- Vertical grid lines: --> <flux:chart.axis.grid /> </flux:chart.axis> <flux:chart.axis axis="y"> <!-- Horizontal grid lines: --> <flux:chart.axis.grid /> </flux:chart.axis></flux:chart.svg>
<!-- A dashed grid line that is 2px wide and has a gray color: --><flux:chart.axis.grid class="text-zinc-200/50" stroke-width="2" stroke-dasharray="4,4" />
<flux:chart.svg> <!-- ... --> <flux:chart.axis axis="x"> <!-- X axis tick mark lines: --> <flux:chart.axis.mark /> <!-- X axis tick labels: --> <flux:chart.axis.tick /> </flux:chart.axis> <flux:chart.axis axis="y"> <!-- Y axis tick mark lines: --> <flux:chart.axis.mark /> <!-- Y axis tick labels: --> <flux:chart.axis.tick /> </flux:chart.axis></flux:chart.svg>
<!-- A tick mark line that is 10px long, 2px wide, and has a gray color: --><flux:chart.axis.mark class="text-zinc-300" stroke-width="2" y1="0" y2="10" />
<!-- A tick label that is 12px, has a blue color, is center aligned, and is 2.5rem from the axis line: --><flux:chart.axis.tick class="text-xs text-blue-500" text-anchor="middle" dy="2.5rem" />
<flux:chart.axis axis="y" tick-count="5"> <!-- ... --></flux:chart.axis>
<flux:chart.axis axis="y" tick-start="min"> <!-- ... --></flux:chart.axis>
<flux:chart.axis axis="y" tick-end="max"> <!-- ... --></flux:chart.axis>
<flux:chart.axis axis="y" tick-values="[0, 128, 256, 384, 512]" tick-suffix="MB"> <!-- ... --></flux:chart.axis>
<flux:chart.svg> <!-- ... --> <!-- Format the X axis tick labels to display the month and day: --> <flux:chart.axis axis="x" :format="['month' => 'long', 'day' => 'numeric']"> <!-- X axis tick labels: --> <flux:chart.axis.tick /> </flux:chart.axis> <!-- Format the Y axis tick labels to display the value in USD: --> <flux:chart.axis axis="y" :format="['style' => 'currency', 'currency' => 'USD']"> <!-- Y axis tick labels: --> <flux:chart.axis.tick /> </flux:chart.axis></flux:chart.svg>
<flux:chart.axis axis="y" tick-prefix="$"> <!-- ... --></flux:chart.axis>
<flux:chart.axis axis="y" tick-suffix="MB"> <!-- ... --></flux:chart.axis>
<flux:chart.svg> <!-- ... --> <flux:chart.cursor /></flux:chart.svg>
<!-- A dashed, black cursor that is 1px wide: --><flux:chart.cursor class="text-zinc-800" stroke-width="1" stroke-dasharray="4,4" />
<flux:chart> <flux:chart.svg> <!-- ... --> </flux:chart.svg> <flux:chart.tooltip> <flux:chart.tooltip.heading field="date" /> <flux:chart.tooltip.value field="visitors" label="Visitors" /> <flux:chart.tooltip.value field="views" label="Views" :format="['notation' => 'compact']" /> </flux:chart.tooltip></flux:chart>
<flux:chart.tooltip> <flux:chart.tooltip.heading field="date" /> <flux:chart.tooltip.value field="visitors" label="Visitors" /> <flux:chart.tooltip.value field="views" label="Page Views" :format="['notation' => 'compact']" /></flux:chart.tooltip>
<flux:chart wire:model="data"> <flux:chart.viewport class="aspect-3/1"> <flux:chart.svg> <flux:chart.line class="text-blue-500" field="visitors" /> <flux:chart.line class="text-red-500" field="views" /> </flux:chart.svg> </flux:chart.viewport> <div class="flex justify-center gap-4 pt-4"> <flux:chart.legend label="Visitors"> <flux:chart.legend.indicator class="bg-blue-400" /> </flux:chart.legend> <flux:chart.legend label="Views"> <flux:chart.legend.indicator class="bg-red-400" /> </flux:chart.legend> </div></flux:chart>
<flux:chart wire:model="data"> <flux:chart.summary> <flux:chart.summary.value field="visitors" :format="['notation' => 'compact']" /> </flux:chart.summary> <flux:chart.viewport class="aspect-[3/1]"> <!-- ... --> </flux:chart.viewport></flux:chart>
<flux:chart.summary.value field="visitors" fallback="1200" />
<flux:chart.axis axis="y" :format="['style' => 'currency', 'currency' => 'USD']" />
Description
|
Example Input
|
Example Output
|
Format Array
|
---|---|---|---|
Currency (USD) | 1234.56 | ['style' => 'currency', 'currency' => 'USD'] | |
Currency (EUR) | 1234.56 | ['style' => 'currency', 'currency' => 'EUR'] | |
Percent | 0.85 | ['style' => 'percent'] | |
Compact Number | 1000000 | ['notation' => 'compact'] | |
Scientific | 123456789 | ['notation' => 'scientific'] | |
Fixed Decimal | 3.1415926535 | ['maximumFractionDigits' => 2] | |
Thousands Separator | 1234567 | ['useGrouping' => true] | |
Custom Unit | 50 | ['style' => 'unit', 'unit' => 'megabyte'] |
<flux:chart.axis axis="x" field="date" :format="['month' => 'long', 'day' => 'numeric']" />
Description
|
Example Input
|
Example Output
|
Format Array
|
---|---|---|---|
Full Date | 2024-03-15 | ['dateStyle' => 'full'] | |
Month and Day | 2024-03-15 | ['month' => 'long', 'day' => 'numeric'] | |
Short Month | 2024-03-15 | ['month' => 'short', 'day' => 'numeric'] | |
Time Only | 2024-03-15 14:30 | ['hour' => 'numeric', 'minute' => 'numeric', 'hour12' => true] | |
24-hour Time | 2024-03-15 14:30 | ['hour' => '2-digit', 'minute' => '2-digit', 'hour12' => false] | |
Weekday | 2024-03-15 | ['weekday' => 'long'] | |
Short Date | 2024-03-15 | ['month' => '2-digit', 'day' => '2-digit', 'year' => '2-digit'] | |
Year Only | 2024-03-15 | ['year' => 'numeric'] |
Prop
|
Description
|
---|---|
wire:model |
Binds the chart to a Livewire property containing the data to display. See the wire:model documentation for more information.
|
value |
Array of data points for the chart. Each point should be an associative array with named fields. Used when not binding with wire:model.
|
curve |
Default line curve type for all lines in the chart. Options: none (default), smooth.
|
Slot
|
Description
|
---|---|
default |
Chart components to render. Typically contains a flux:chart.svg component that defines the chart structure.
|
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the chart container. Common uses: aspect-3/1 for aspect ratio, h-64 for fixed height.
|
Attribute
|
Description
|
---|---|
data-flux-chart |
Applied to the root element for styling and identification.
|
Container for the chart's SVG elements. This component must be included within a `flux:chart` to render the chart.
Slot
|
Description
|
---|---|
default |
Chart visualization components like lines, areas, axes, and interactive elements.
|
Prop
|
Description
|
---|---|
field |
Name of the data field to plot on the y-axis. Required.
|
curve |
Line curve type. Options: none (default), smooth.
|
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the line. Common use: text-{color} for line color.
|
Prop
|
Description
|
---|---|
field |
Name of the data field to plot on the y-axis. Required.
|
curve |
Area curve type. Options: none (default), smooth.
|
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the area. Common use: fill-{color}/20 for fill color.
|
Adds points (dots) to mark data points on a line or area chart.
Prop
|
Description
|
---|---|
field |
Name of the data field to plot points for. Required.
|
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the points. Common use: fill-{color} for point fill color, r attribute for point radius.
|
Prop
|
Description
|
---|---|
axis |
Axis to configure. Options: x, y. Required.
|
field |
For x-axis, the data field to use for labels.
|
format |
Date/number formatting options for axis labels. See Formatting for more details.
|
Adds tick marks to the chart. Must be used within a `flux:chart.axis` component.
Prop
|
Description
|
---|---|
position |
Position of the tick marks. Options: top, bottom, left, right.
|
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the tick marks. Common use: text-{color} for line color, stroke-width="1" for line thickness.
|
Adds an axis line to the chart. Must be used within a `flux:chart.axis` component.
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the axis line. Common use: text-{color} for line color, stroke-width="1" for line thickness.
|
Adds gridlines to the chart. Must be used within a `flux:chart.axis` component.
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the gridlines. Common use: text-{color} for line color, stroke-width="{width}" for line thickness.
|
Adds tick marks and labels to an axis. Must be used within a `flux:chart.axis` component.
Prop
|
Description
|
---|---|
format |
Date/number formatting options for tick labels. See Formatting for more details.
|
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the tick marks and labels. Common use: text-{color} for label color, font-{weight} for label weight.
|
Adds a horizontal line at y=0. Useful for charts that contain both positive and negative values.
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the zero line. Common use: text-{color} for line color, stroke-width="{width}" for line thickness.
|
Prop
|
Description
|
---|---|
field |
Data field to display in the tooltip.
|
format |
Date/number formatting options for tooltip values.
|
Prop
|
Description
|
---|---|
field |
Data field to display in the tooltip heading.
|
format |
Date/number formatting options for tooltip values. See Formatting for more details.
|
Prop
|
Description
|
---|---|
field |
Data field to display in the tooltip.
|
format |
Date/number formatting options for tooltip values. See Formatting for more details.
|
Adds an interactive cursor that follows mouse movement over the chart. Activates tooltips when present.
CSS
|
Description
|
---|---|
class |
Additional CSS classes applied to the cursor line.
|
Adds a summary section typically shown above the chart. Shows the latest values or values at cursor position.
Slot
|
Description
|
---|---|
default |
Content to display in the summary section. Can include flux:chart.value components to display specific data values.
|
Displays a specific data value, typically used within a `flux:chart.summary` component.
Prop
|
Description
|
---|---|
field |
Data field to display.
|
fallback |
Fallback text to display if the value is not found or cannot be formatted.
|
format |
Date/number formatting options. See Formatting for more details.
|
Prop
|
Description
|
---|---|
field |
Data field this legend item represents.
|
label |
Label text for the legend item.
|
format |
Date/number formatting options. See Formatting for more details.
|
Slot
|
Description
|
---|---|
default |
Content to display in the legend. Can include arbitrary content, including flux:chart.legend.indicator components.
|