PictorialBar.jsx 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import React from 'react';
  2. import { Card } from 'antd';
  3. import * as echarts from 'echarts/core';
  4. import Chart from '@/components/chart';
  5. export default (props) => {
  6. let category = [];
  7. let dottedBase = +new Date();
  8. let lineData = [];
  9. let barData = [];
  10. for (let i = 0; i < 20; i++) {
  11. let date = new Date((dottedBase += 3600 * 24 * 1000));
  12. category.push(
  13. [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-')
  14. );
  15. let b = Math.random() * 200;
  16. let d = Math.random() * 200;
  17. barData.push(b);
  18. lineData.push(d + b);
  19. }
  20. const option = {
  21. backgroundColor: '#0f375f',
  22. tooltip: {
  23. trigger: 'axis',
  24. axisPointer: {
  25. type: 'shadow'
  26. }
  27. },
  28. legend: {
  29. data: ['line', 'bar'],
  30. textStyle: {
  31. color: '#ccc'
  32. }
  33. },
  34. xAxis: {
  35. data: category,
  36. axisLine: {
  37. lineStyle: {
  38. color: '#ccc'
  39. }
  40. }
  41. },
  42. yAxis: {
  43. splitLine: { show: false },
  44. axisLine: {
  45. lineStyle: {
  46. color: '#ccc'
  47. }
  48. }
  49. },
  50. series: [
  51. {
  52. name: 'line',
  53. type: 'line',
  54. smooth: true,
  55. showAllSymbol: true,
  56. symbol: 'emptyCircle',
  57. symbolSize: 15,
  58. data: lineData
  59. },
  60. {
  61. name: 'bar',
  62. type: 'bar',
  63. barWidth: 10,
  64. itemStyle: {
  65. borderRadius: 5,
  66. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  67. { offset: 0, color: '#14c8d4' },
  68. { offset: 1, color: '#43eec6' }
  69. ])
  70. },
  71. data: barData
  72. },
  73. {
  74. name: 'line',
  75. type: 'bar',
  76. barGap: '-100%',
  77. barWidth: 10,
  78. itemStyle: {
  79. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  80. { offset: 0, color: 'rgba(20,200,212,0.5)' },
  81. { offset: 0.2, color: 'rgba(20,200,212,0.2)' },
  82. { offset: 1, color: 'rgba(20,200,212,0)' }
  83. ])
  84. },
  85. z: -12,
  86. data: lineData
  87. },
  88. {
  89. name: 'dotted',
  90. type: 'pictorialBar',
  91. symbol: 'rect',
  92. itemStyle: {
  93. color: '#0f375f'
  94. },
  95. symbolRepeat: true,
  96. symbolSize: [12, 4],
  97. symbolMargin: 1,
  98. z: -10,
  99. data: lineData
  100. }
  101. ]
  102. };
  103. return (
  104. <Card title='Pictorial Chart'>
  105. <Chart option={option} style={props.style}></Chart>
  106. </Card>
  107. )
  108. }