Coder Social home page Coder Social logo

yii2-highcharts's Introduction

Yii2 Highcharts Widget

Latest Stable Version Total Downloads License Scrutinizer Code Quality

Easily add Highcharts, Highstock and Highmaps graphs to your Yii2 application.

Screen Shot

About

Highcharts

Create interactive charts easily for your web projects. Used by tens of thousands of developers and 59 out of the world's 100 largest companies, Highcharts is the simplest yet most flexible charting API on the market.

Highstock

Highstock lets you create stock or general timeline charts in pure JavaScript. Including sophisticated navigation options like a small navigator series, preset date ranges, date picker, scrolling and panning.

Highmaps

Build interactive maps to display sales, election results or any other information linked to geography. Perfect for standalone use or in dashboards in combination with Highcharts!

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist miloschuman/yii2-highcharts-widget "dev-master"

or add

"miloschuman/yii2-highcharts-widget": "dev-master"

to the require section of your composer.json file.

Usage

Preferred Method (using PHP arrays)

To use this widget, insert the following code into a view file:

use miloschuman\highcharts\Highcharts;

echo Highcharts::widget([
   'options' => [
      'title' => ['text' => 'Fruit Consumption'],
      'xAxis' => [
         'categories' => ['Apples', 'Bananas', 'Oranges']
      ],
      'yAxis' => [
         'title' => ['text' => 'Fruit eaten']
      ],
      'series' => [
         ['name' => 'Jane', 'data' => [1, 0, 4]],
         ['name' => 'John', 'data' => [5, 7, 3]]
      ]
   ]
]);

By configuring the options property, you can specify the options that need to be passed to the Highcharts JavaScript object. Please refer to the demo gallery and documentation on the Highcharts website for possible options.

See /doc/examples for more usage examples.

Alternative Method (using JSON string)

Alternatively, you can use a valid JSON string in place of an associative array to specify options:

Highcharts::widget([
   'options'=>'{
      "title": { "text": "Fruit Consumption" },
      "xAxis": {
         "categories": ["Apples", "Bananas", "Oranges"]
      },
      "yAxis": {
         "title": { "text": "Fruit eaten" }
      },
      "series": [
         { "name": "Jane", "data": [1, 0, 4] },
         { "name": "John", "data": [5, 7,3] }
      ]
   }'
]);

Note: You must provide a valid JSON string (with double quotes) when using the second option. You can quickly validate your JSON string online using JSONLint.

Just the Assets

If you merely want to include the Highcharts/Highstock/Highmaps javascript libraries in your view, you can bypass the widget and access the asset bundle directly:

use miloschuman\highcharts\HighchartsAsset;

HighchartsAsset::register($this)->withScripts(['highstock', 'modules/exporting', 'modules/drilldown']);

In this scenario, you would need to write and include your own JavaScript to display the charts, just as illustrated in the Highcharts Demo, Highstock Demo and Highmaps Demo pages.

Tips

  • If you need to use JavaScript in any of your configuration options, use Yii's [[JsExpression]] object. For instance:

    ...
    'tooltip' => [
       'formatter' => new JsExpression('function(){ return this.series.name; }')
    ],
    ...

    Note, this is currently only possible when using a PHP associative array (Preferred Method) for configuration.

  • Highcharts by default displays a small credits label in the lower right corner of the chart. This can be removed using the following top-level option.

    ...
    'credits' => ['enabled' => false],
    ...
  • All adapters, modules, themes, and supplementary chart types must be enabled through the top-level 'scripts' option.

    ...
    'scripts' => [
       'highcharts-more',   // enables supplementary chart types (gauge, arearange, columnrange, etc.)
       'modules/exporting', // adds Exporting button/menu to chart
       'themes/grid'        // applies global 'grid' theme to all charts
    ],
    ...

    For a list of available scripts, see the contents of vendor/miloschuman/yii2-highcharts-widget/src/assets/.

Change Log

v4.0.4 (2014-09-25)

  • Upgraded Highcharts core library to the latest release (4.0.4). See the Highcharts changelog for more information about what's new in this version.
  • Added usage examples in /doc/examples.
  • Added HighmapsWidget. See included Highmaps Widget Example for usage.
  • Added callback option to make AJAX loading easier. See included Highstock Widget Example for usage.

v4.0.1 (2014-04-24)

  • Upgraded Highcharts core library to the latest release (4.0.1).

v3.0.10 (2014-03-17)

  • Upgraded Highcharts core library to the latest release (3.0.10).

v3.0.9 (2014-02-17)

  • Upgraded Highcharts core library to the latest release (3.0.9).

yii2-highcharts's People

Contributors

miloschuman avatar demogorgorn avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar Ibrar Turi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.