Skip to content

Dataset API

Dataset is the value object representing a single series in a chart. It’s used inside class-based chart definitions and returned implicitly by Chart::dataset().

use Matheusmarnt\LiveCharts\Charts\Dataset;
$dataset = Dataset::make('Revenue')
->data([1200, 1900, 3000])
->color('#10B981');
MethodSignatureDescription
make()static make(string $name): selfCreate a new dataset with a label.
data()data(array $values): selfSet the numeric values.
color()color(string $hex): selfSingle colour for the whole series.
colors()colors(array $hexes): selfPer-point colours (e.g. for bar charts).
type()type(string $type): selfOverride the type for mixed-type charts.
meta()meta(array $meta): selfArbitrary engine-specific options merged into the payload.

type() lets you build combined visualisations like a bar + line overlay:

public function datasets(): array
{
return [
Dataset::make('Sales')->type('bar')->data([100, 200, 150]),
Dataset::make('Trend')->type('line')->data([110, 180, 160]),
];
}

Engine support varies — ApexCharts handles this via chart.type = 'line' plus per-series type. Chart.js handles it via per-dataset type on a base bar chart. Both are covered by the adapter.

Use meta() to pass keys the abstraction doesn’t model directly:

Dataset::make('Revenue')
->data([10, 20, 30])
->meta([
'fill' => true,
'tension' => 0.4,
]);

The adapter merges meta into the engine’s dataset config object.