# Graph widget

This widget intends to display a graph visualization of any data.

# Types

There are two graph types, and they share the exact same API. To choose one or the other, use its dedicated class:

# Line graph


# Bar graph


# Pie graph


# Attributes (setters)

# setRatio(string $ratio)

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.

# Data valuation

Valuation is handled by a dedicated $this->addGraphDataSet(string $graphWidgetKey, SharpGraphWidgetDataSet $dataSet) in the Dashboard class:


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 label
  • setColor(string $color), where $color can be an HTML constant or an hexadecimal value, to set the data color.

You can chain calls to addGraphDataSet() to add multiple data sets, with different colors and labels.