index.js 929 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import './index.less';
  3. import echarts from 'echarts/lib/echarts';
  4. import ReactEchartsCore from 'echarts-for-react/lib/core';
  5. import 'echarts/lib/chart/line';
  6. import 'echarts/lib/component/tooltip';
  7. import 'echarts/lib/component/title';
  8. import 'echarts/lib/component/legend';
  9. function LineChart(props) {
  10. const { className = '', theme = 'shine', option = {}, data = [] } = props;
  11. let defaultOption = {
  12. series: [
  13. {
  14. data: [],
  15. type: 'line',
  16. smooth: true,
  17. },
  18. ],
  19. xAxis: {
  20. type: 'key',
  21. },
  22. yAxis: {
  23. type: 'value',
  24. },
  25. };
  26. if (data.length > 0) {
  27. defaultOption.series.data = data;
  28. } else {
  29. defaultOption = option;
  30. }
  31. return (
  32. <div className={`line-chart ${className}`}>
  33. <ReactEchartsCore echarts={echarts} option={defaultOption} notMerge lazyUpdate theme={theme} />
  34. </div>
  35. );
  36. }
  37. export default LineChart;