Download the PHP package sibilino/yii2-dygraphswidget without Composer
On this page you can find all versions of the php package sibilino/yii2-dygraphswidget. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-dygraphswidget
Dygraphs Widget for Yii 2
A simple graph widget for Yii 2, based on [Dygraphs] (http://dygraphs.com/).
Changelog
Installation
Composer
Add sibilino/yii2-dygraphswidget to your composer.json file and perform a Composer Update as usual.
Manually
If for some reason you cannot or do not want to use Composer, then you must create the widget folder manually, and then configure your Yii application to autoload the widget classes.
First, create the folder structure sibilino/yii2-dygraphswidget/widget inside the vendor subfolder of your Yii application.
Then, download the widget .zip file and extract the contents of its widget subfolder into the folder you created in the previous step.
Next, edit config/web.php and add the following entry:
Finally, remember to use the namespace sibilino\y2dygraphs when you call the widget.
Usage
In your view, create the widget with your data matrix as its data option.
Dygraphs options
You can set the options property to pass additional options to the Dygraphs object:
Data formats
The data to display in the widget can be specified in several ways. Consider the following examples, and make sure to read [the official documentation] (http://dygraphs.com/data.html) for more details:
-
Matrix
-
URL URL to a text file with the data.
-
Model attribute Specify the
model
andattribute
configuration parameters to take the data from an attribute of ayii\base\Model
object: -
Data Provider The
data
property can contain a Data Provider (implementingyii\data\DataProviderInterface
). In this case, the data matrix will be generated from the models provided by the Data Provider. Each data row will contain the values of the attributes of one model. By default, all attributes of every model will be used, but you can configure theattributes
property to specify the list of attributes to appear in a row (the specified order will be taken into account). - JavaScript JS code that returns a data object usable by Dygraphs. The code must be wrapped inside a JsExpression object:
Additional options
The following widget properties can also be specified:
- xIsDate: Set this property to true if the x-values (first value in each row of the data matrix) are date strings, in order to properly convert them to JS date objects for Dygraphs.
- scriptUrl: The URL where the Dygraphs.js library is taken from. If not set, the widget will locally publish its own distribution of the Dygraphs library.
- model and attribute: Specify a
yii\base\Model
instance and one of its attributes in order to take the data from it. - attributes: To be used when
data
contains a data provider. Configureattributes
with a list of the model attributes that will be in every row of the data matrix. If this list is empty, all attributes will be taken. - jsVarName: Specifies a custom name for the JS variable that will receive the Dygraphs object upon creation.
- htmlOptions: Additional HTML attributes for the graph-containing div.
JavaScript code in options
Anytime you need to pass JavaScript code (for example, passing a function to an option), just pass a new JsExpression($your_js_code). For example:
Visibility checkboxes
It is often useful to hide and show some of the dataseries in a chart. The widget features helper scripts to easily control series visibily with checkboxes.
To use this feature, make sure your page has one checkbox per series in the chart, and give each checkbox an id
attribute with the index of the series controlled by it.
Then, configure the widget with a checkBoxSelector
that matches the group of checkboxes. For example, for a chart with 2 data series:
The attribute that associates a checkbox with a data series (id
in the example) can be changed by configuring checkBoxReferenceAttr
.