Datasets

Datasets represent individual series of data within a chart. Each dataset is a Visualizable that carries a SQL expression which is selected from the base query and returned as part of the chart payload. The dataset type tells the front end how to render the series.

Dataset Types

Dataset TypeDescription
LineRenders data as a line series.
BarRenders data as a bar series.
PieRenders data as a pie chart segment.
DoughnutRenders data as a doughnut chart segment.
ScatterRenders data as scatter plot points.
AreaRenders data as a filled area series.

Usage

Datasets are defined in the getDatasets method of your chart class:

php
use Illuminate\Support\Collection;
use SettleUp\Visualizations\Charts\Datasets\Bar;
use SettleUp\Visualizations\Charts\Datasets\Line;

public function getDatasets(): Collection
{
    return collect([
        Bar::make('SUM(orders.total)', 'Total Revenue'),
        Line::make('COUNT(orders.id)', 'Order Count'),
    ]);
}

The first argument is the SQL expression, and the second is the field name used in the schema and output.

Customization Methods

Some dataset types provide additional methods to control their rendering:

Line

php
use SettleUp\Visualizations\Charts\Datasets\Line;

// Control line curvature (0 = straight, 1 = maximum curve)
Line::make('COUNT(orders.id)', 'Order Count')
    ->tension(0.4);

// Fill the area beneath the line
Line::make('COUNT(orders.id)', 'Order Count')
    ->filled();

Bar

php
use SettleUp\Visualizations\Charts\Datasets\Bar;

// Stack bars with other stacked series
Bar::make('SUM(orders.total)', 'Revenue')
    ->stacked();

// Assign to a named stack group
Bar::make('SUM(orders.total)', 'Revenue')
    ->stackGroup('financial');

Doughnut

php
use SettleUp\Visualizations\Charts\Datasets\Doughnut;

// Set the cutout percentage (size of the hole)
Doughnut::make('COUNT(tasks.id)', 'Tasks')
    ->cutout('50%');

Area

php
use SettleUp\Visualizations\Charts\Datasets\Area;

// Control line curvature (0 = straight, 1 = maximum curve)
Area::make('SUM(orders.total)', 'Revenue')
    ->tension(0.4);

Pie, Scatter

The Pie and Scatter dataset types do not have additional customization methods beyond the base Visualizable functionality (metadata, headers).

Extending Datasets

Datasets support macros, allowing you to add custom methods:

php
use SettleUp\Visualizations\Charts\Datasets\Bar;

Bar::macro('withColor', function (string $color) {
    return $this->meta('color', $color);
});

// Usage
Bar::make('SUM(orders.total)', 'Revenue')->withColor('#4CAF50');