indexecharts.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Component, PropsWithChildren } from 'react'
  2. import { View, Text } from '@tarojs/components'
  3. import * as echarts from '../../lib/ec-canvas/echarts'
  4. import './index.scss'
  5. export default class Index extends Component {
  6. // this.state = {
  7. // ec:{
  8. // onInit:function(){}
  9. // }
  10. // }
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. ec: {
  15. onInit: function (canvas, width, height) {
  16. const chart = echarts.init(canvas, null, {
  17. width: width,
  18. height: height
  19. });
  20. canvas.setChart(chart);
  21. const option = {
  22. title: {
  23. text: 'ECharts 入门示例'
  24. },
  25. tooltip: {},
  26. legend: {
  27. data: ['销量']
  28. },
  29. xAxis: {
  30. data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
  31. },
  32. yAxis: {},
  33. series: [
  34. {
  35. name: '销量',
  36. type: 'bar',
  37. data: [5, 20, 36, 10, 10, 20]
  38. }
  39. ]
  40. };
  41. chart.setOption(option)
  42. return chart;
  43. }
  44. }
  45. }
  46. }
  47. componentDidMount() { }
  48. componentWillUnmount() { }
  49. componentDidShow() { }
  50. componentDidHide() { }
  51. callback(e){
  52. }
  53. render() {
  54. return (
  55. <View className='index'>
  56. <Text>Hello world!</Text>
  57. <View className='canvas-container'>
  58. <ec-canvas id='mychart-dom-bar' canvas-id='mychart-bar' ec={this.state.ec}></ec-canvas>
  59. </View>
  60. <demo content="hi" detail={{a:'1',b:2}} onApple={(e)=>{
  61. debugger
  62. }}/>
  63. <Text>Just say hi</Text>
  64. <View className='demo'></View>
  65. </View>
  66. )
  67. }
  68. }