项目作者: daixianceng

项目描述 :
ECharts widget for Yii2.
高级语言: PHP
项目地址: git://github.com/daixianceng/yii2-echarts.git
创建时间: 2016-03-22T10:39:35Z
项目社区:https://github.com/daixianceng/yii2-echarts

开源协议:BSD 3-Clause "New" or "Revised" License

下载


yii2-echarts

Latest Stable Version Total Downloads Latest Unstable Version License

ECharts widget for Yii2.

See the echarts project for details.

Installation

The preferred way to install this extension is through composer.

Either run

  1. php composer.phar require --prefer-dist daixianceng/yii2-echarts "*"

or add

  1. "daixianceng/yii2-echarts": "*"

to the require section of your composer.json file.

Usage

Example

  1. <?php
  2. use yii\web\JsExpression;
  3. use daixianceng\echarts\ECharts;
  4. ?>
  5. <?= ECharts::widget([
  6. 'responsive' => true,
  7. 'options' => [
  8. 'style' => 'height: 400px;'
  9. ],
  10. 'pluginEvents' => [
  11. 'click' => [
  12. new JsExpression('function (params) {console.log(params)}'),
  13. new JsExpression('function (params) {console.log("ok")}')
  14. ],
  15. 'legendselectchanged' => new JsExpression('function (params) {console.log(params.selected)}')
  16. ],
  17. 'pluginOptions' => [
  18. 'option' => [
  19. 'title' => [
  20. 'text' => '折线图堆叠'
  21. ],
  22. 'tooltip' => [
  23. 'trigger' => 'axis'
  24. ],
  25. 'legend' => [
  26. 'data' => ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
  27. ],
  28. 'grid' => [
  29. 'left' => '3%',
  30. 'right' => '4%',
  31. 'bottom' => '3%',
  32. 'containLabel' => true
  33. ],
  34. 'toolbox' => [
  35. 'feature' => [
  36. 'saveAsImage' => []
  37. ]
  38. ],
  39. 'xAxis' => [
  40. 'name' => '日期',
  41. 'type' => 'category',
  42. 'boundaryGap' => false,
  43. 'data' => ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  44. ],
  45. 'yAxis' => [
  46. 'type' => 'value'
  47. ],
  48. 'series' => [
  49. [
  50. 'name' => '邮件营销',
  51. 'type' => 'line',
  52. 'stack' => '总量',
  53. 'data' => [120, 132, 101, 134, 90, 230, 210]
  54. ],
  55. [
  56. 'name' => '联盟广告',
  57. 'type' => 'line',
  58. 'stack' => '总量',
  59. 'data' => [220, 182, 191, 234, 290, 330, 310]
  60. ],
  61. [
  62. 'name' => '视频广告',
  63. 'type' => 'line',
  64. 'stack' => '总量',
  65. 'data' => [150, 232, 201, 154, 190, 330, 410]
  66. ],
  67. [
  68. 'name' => '直接访问',
  69. 'type' => 'line',
  70. 'stack' => '总量',
  71. 'data' => [320, 332, 301, 334, 390, 330, 320]
  72. ],
  73. [
  74. 'name' => '搜索引擎',
  75. 'type' => 'line',
  76. 'stack' => '总量',
  77. 'data' => [820, 932, 901, 934, 1290, 1330, 1320]
  78. ]
  79. ]
  80. ]
  81. ]
  82. ]); ?>

Using themes

  1. <?php
  2. use daixianceng\echarts\ECharts;
  3. // Registers the theme JS files.
  4. ECharts::registerTheme('dark');
  5. ?>
  6. <?= ECharts::widget([
  7. 'theme' => 'dark',
  8. 'responsive' => true,
  9. 'options' => [
  10. 'style' => 'height: 400px;'
  11. ],
  12. 'pluginOptions' => [
  13. 'option' => []
  14. ]
  15. ]); ?>

Using maps

  1. <?php
  2. use daixianceng\echarts\ECharts;
  3. // 引用地图必须使用完整版的echarts
  4. ECharts::$dist = ECharts::DIST_FULL;
  5. ECharts::registerMap(['china', 'province/beijing']);
  6. ?>
  7. <?= ECharts::widget([
  8. 'responsive' => true,
  9. 'options' => [
  10. 'style' => 'height: 400px;'
  11. ],
  12. 'pluginOptions' => [
  13. 'option' => [
  14. 'series' => [
  15. [
  16. 'name' => 'China map',
  17. 'type' => 'map',
  18. 'map' => 'china',
  19. 'data' => [
  20. ['name' => '广东', 'selected' => true]
  21. ]
  22. ]
  23. ]
  24. ]
  25. ]
  26. ]); ?>
  27. <?= ECharts::widget([
  28. 'responsive' => true,
  29. 'options' => [
  30. 'style' => 'height: 400px;'
  31. ],
  32. 'pluginOptions' => [
  33. 'option' => [
  34. 'geo' => [
  35. 'map' => '北京'
  36. ]
  37. ]
  38. ]
  39. ]); ?>

Configure CDN

  1. <?php
  2. return [
  3. 'components' => [
  4. 'assetManager' => [
  5. 'class' => 'yii\web\AssetManager',
  6. 'bundles' => [
  7. 'daixianceng\echarts\EChartsAsset' => [
  8. 'sourcePath' => null,
  9. 'baseUrl' => 'https://cdn.jsdelivr.net/npm/echarts@4.7.0/dist'
  10. ]
  11. ],
  12. ],
  13. ],
  14. ];
  15. ?>

License

yii2-echarts is released under the BSD-3-Clause License. See the bundled LICENSE for details.