This widget intends to display a graph visualization of any data.
There are two graph types, and they share the exact same API. To choose one or the other, use its dedicated class:
$this->addWidget(
SharpLineGraphWidget::make("capacities");
);
$this->addWidget(
SharpBarGraphWidget::make("capacities");
);
$this->addWidget(
SharpPieGraphWidget::make("capacities");
);
This attribute is used to define the graph ratio, which will be consistent in responsive mode. The expected format is width:height
, so for instance 16:9
(the default) or 4:3
.
Valuation is handled by a dedicated $this->addGraphDataSet(string $graphWidgetKey, SharpGraphWidgetDataSet $dataSet)
in the Dashboard class:
$this->addGraphDataSet(
"capacities",
SharpGraphWidgetDataSet::make($values)
->setLabel("Capacities")
->setColor("blue")
);
We use an instance of Code16\Sharp\Dashboard\Widgets\SharpGraphWidgetDataSet
to handle graph data. This object is built with a $values
array which must contain numeric values.
SharpGraphWidgetDataSet
defines two useful setters:
setLabel(string $label)
to set the legend labelsetColor(string $color)
, where $color can be an HTML constant or an hexadecimal value, to set the data color.
You can chain call to addGraphDataSet()
to add multiple data sets, with different colors and labels.