chart 图表

解释:图表组件,提供了常规的折线图、柱状图、饼图,支持 SVG + Canvas 两种渲染引擎,使用扁平化数据配置完成开发。

属性说明

属性名类型必填默认值说明

chartOptions

Object

图表数据及样式参数

chartOptions 有效值

属性名类型必填默认值说明

canvasWidth

Number

canvas 宽度(单位:px)

canvasHiehgt

Number

canvas 高度(单位:px)

canvasId

String

canvasId

animation

Number

10000

canvas 动画持续时长(单位:ms)

renderType

String

canvas

图表渲染类型,支持 canvas,svg 两种

type

String

line

渲染类型,支持 line(折线图)、pie(饼图)、 bar(柱图)

startAngle

Number

-180

饼图起始渲染角度

radius

String

是否支持环图,[80, 90] 数组值代表圆半径

legend

Object

{
  show: true
}

tooltip

Object

{
  show: true
}

yAxis

Object

柱图 yAxis 与 xAxis 可以类型互换,实现竖向和横向柱图切换
{
  type: ‘value’
}

xAxis

String

{
  type: ‘category’,
  data: [‘2017’, ‘2018’, ‘2019’, ‘2020’]
}

series

String

折线 or 柱状图数据
[{  
  name: ‘成交量1’,
  data: [42, 26, 17, 32]
},
{  
  name: ‘成交量1’,
  data: [42, 26, 17, 32]
}]
饼图数据
[{  
  name: ‘成交量1’,
  data: 1
},
{  
  name: ‘成交量1’,
  data: 2
},
{  
  name: ‘成交量1’,
  data: 3
}]

styleConfig

Object

目前支持设置图表色值
{
  color: [‘#3388ff’, ‘#ff4040’, …]
}

示例

跳转编辑工具

在开发者工具中打开

在 WEB IDE 中打开

扫码体验

代码示例

百度智能小程序

请使用百度APP扫码

代码示例

  • SWAN
  • JS
  • CSS
  • JSON
  1. <view class="chart-container">
  2. <view class="tab">折线图</view>
  3. <view>
  4. <view class="container-chart">
  5. <div class="btn-group">
  6. <button type="primary" bindtap="showViewM2" data-type="single">单折线图</button>
  7. <button type="defualt" bindtap="showViewM2" data-type="multi">复合折线图</button>
  8. </div>
  9. <view class="chart-single-content">
  10. <smt-chart chart-options="{{m2Chartoptions}}" />
  11. </view>
  12. </view>
  13. <view class="setting">
  14. <view class="item-title item-scroll block border-bottom">自定义样式</view>
  15. <view class="item-scroll block border-bottom">
  16. <text class="switch-text">显示图例(Lenged)</text>
  17. <switch bindchange="changeLengendM2" checked></switch>
  18. </view>
  19. <view class="item-scroll block border-bottom">
  20. <text class="switch-text">负值状态</text>
  21. <switch bindchange="changeNegativeValueM2"></switch>
  22. </view>
  23. <view class="item-scroll block border-bottom">
  24. <text class="switch-text">正负值状态</text>
  25. <switch bindchange="changeCrossValueM2"></switch>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="tab">柱状图</view>
  30. <view>
  31. <view class="container-chart">
  32. <div class="btn-group">
  33. <button type="primary" bindtap="showViewM1" data-active-name="m1" data-type="single">单柱图</button>
  34. <button type="defualt" bindtap="showViewM1" data-active-name="m1" data-type="multi">复合柱图</button>
  35. </div>
  36. <view class="chart-single-content">
  37. <smt-chart chart-options="{{m1Chartoptions}}" />
  38. </view>
  39. </view>
  40. <view class="setting">
  41. <view class="item-title item-scroll block border-bottom">自定义样式</view>
  42. <view class="item-scroll block border-bottom">
  43. <text class="switch-text">柱图横向展示</text>
  44. <switch bindchange="changeZoom"></switch>
  45. </view>
  46. <view class="item-scroll block border-bottom">
  47. <text class="switch-text">显示图例(Lenged)</text>
  48. <switch bindchange="changeLengendM1" checked></switch>
  49. </view>
  50. <view class="item-scroll block border-bottom">
  51. <text class="switch-text">负值状态</text>
  52. <switch bindchange="changeNegativeValueM1"></switch>
  53. </view>
  54. <view class="item-scroll block border-bottom">
  55. <text class="switch-text">正负值状态</text>
  56. <switch bindchange="changeCrossValueM1"></switch>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="tab">饼状图</view>
  61. <view>
  62. <view class="container-chart">
  63. <div class="btn-group">
  64. <button type="primary" bindtap="showViewM3" data-type="single">饼状图</button>
  65. <button type="defualt" bindtap="showViewM3" data-type="multi">环状图</button>
  66. </div>
  67. <view class="chart-single-content">
  68. <smt-chart chart-options="{{m3Chartoptions}}" />
  69. </view>
  70. </view>
  71. <view class="setting">
  72. <view class="item-title item-scroll block border-bottom">自定义样式</view>
  73. <view class="item-scroll block border-bottom">
  74. <text class="switch-text">显示图例(Lenged)</text>
  75. <switch bindchange="changeLengendM3" checked></switch>
  76. </view>
  77. </view>
  78. </view>
  79. </view>