index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/pie';
  6. import 'echarts/lib/component/tooltip';
  7. import 'echarts/lib/component/title';
  8. import 'echarts/lib/component/legend';
  9. function PieChart(props) {
  10. const { className = '', theme = 'shine', option = {}, data = [], width, height } = props;
  11. let defaultOption = {
  12. series: [
  13. {
  14. data: [],
  15. type: 'pie',
  16. },
  17. ],
  18. xAxis: {
  19. type: 'key',
  20. },
  21. yAxis: {
  22. type: 'value',
  23. },
  24. };
  25. if (data.length > 0) {
  26. defaultOption.series.data = data;
  27. } else {
  28. defaultOption = option;
  29. }
  30. const style = {};
  31. if (width) style.width = width;
  32. if (height) style.height = height;
  33. return (
  34. <div className={`pie-chart ${className}`}>
  35. <ReactEchartsCore
  36. echarts={echarts}
  37. option={defaultOption}
  38. style={style}
  39. opts={style}
  40. notMerge
  41. lazyUpdate
  42. theme={theme}
  43. />
  44. </div>
  45. );
  46. }
  47. export default PieChart;