ChartJs Widget

What is the ChartJs Widget?

The ChartJs widget allows you to make use of the ChartJs plugin in your Yii 2 apps.

Installation

The preferred way to install this extension is through composer.

Either run

composer require 2amigos/yii2-chartjs-widget:~2.0

or add the following to the require section of your application's composer.json file:

"2amigos/yii2-chartjs-widget" : "~2.0"

Usage example

The following types are supported:

  • Line
  • Bar
  • Radar
  • Polar
  • Pie
  • Doughnut

The following example is using the Line type of chart. Please, check ChartJs plugin documentation for the different types supported by the plugin.

<?php
use dosamigos\chartjs\ChartJs;
?>

<?= ChartJs::widget([
    'type' => 'Line',
    'options' => [
        'height' => 400,
        'width' => 400
    ],
    'data' => [
        'labels' => ["January", "February", "March", "April", "May", "June", "July"],
        'datasets' => [
            [
                'fillColor' => "rgba(220,220,220,0.5)",
                'strokeColor' => "rgba(220,220,220,1)",
                'pointColor' => "rgba(220,220,220,1)",
                'pointStrokeColor' => "#fff",
                'data' => [65, 59, 90, 81, 56, 55, 40]
            ],
            [
                'fillColor' => "rgba(151,187,205,0.5)",
                'strokeColor' => "rgba(151,187,205,1)",
                'pointColor' => "rgba(151,187,205,1)",
                'pointStrokeColor' => "#fff",
                'data' => [28, 48, 40, 19, 96, 27, 100]
            ]
        ]
    ]
]);
?>

Share this

Contributors Thanks All

 

Do you have a good idea? Why Don't We Talk?