bizcharts 折线图缩放案例
    https://www.bizcharts.net/product/bizcharts/demo/22

    1. import React, { useEffect } from 'react';
    2. import PropTypes from 'prop-types';
    3. import { Empty } from 'antd';
    4. import { Axis, Chart, Geom, Tooltip, Legend } from 'bizcharts';
    5. import Brush from '@antv/g2-brush';
    6. LineChartZoom.propTypes = {
    7. height: PropTypes.number,
    8. padding: PropTypes.array,
    9. custom: PropTypes.bool,
    10. loading: PropTypes.bool,
    11. dataSource: PropTypes.array.isRequired,
    12. };
    13. LineChartZoom.defaultProps = {
    14. height: 460,
    15. padding: [20, 56, 50, 56],
    16. custom: false,
    17. loading: false,
    18. };
    19. let chart;
    20. function LineChartZoom(props) {
    21. const { height, padding, custom, dataSource } = props;
    22. if (!dataSource.length) return <Empty />;
    23. useEffect(() => {
    24. new Brush({
    25. canvas: chart.get('canvas'),
    26. style: {
    27. fill: '#ccc',
    28. fillOpacity: 0.4,
    29. },
    30. chart,
    31. });
    32. // 双击清除过滤,恢复初始状态
    33. chart.on('plotdblclick', () => {
    34. chart.get('options').filters = {};
    35. chart.repaint();
    36. });
    37. }, []);
    38. const scale = {
    39. value: {
    40. alias: '值',
    41. tickCount: 5,
    42. min: 0,
    43. },
    44. date: {
    45. type: 'timeCat',
    46. mask: 'YYYY-MM-DD HH:mm',
    47. tickCount: custom ? 8 : 12,
    48. nice: false,
    49. },
    50. };
    51. const label = {
    52. formatter(text) {
    53. return custom ? text : text.slice(-5);
    54. },
    55. textStyle: {
    56. textAlign: 'center',
    57. fontSize: '12',
    58. },
    59. };
    60. const attr = {
    61. data: dataSource,
    62. scale,
    63. height,
    64. padding,
    65. forceFit: true,
    66. onGetG2Instance: g2Chart => {
    67. g2Chart.animate(false);
    68. chart = g2Chart;
    69. },
    70. };
    71. return (
    72. <Chart {...attr}>
    73. <Axis name='date' label={label} />
    74. <Axis name='value' />
    75. <Tooltip crosshairs={false}/>
    76. <Legend />
    77. <Geom type='line' position='date*value' size={2} shape='smooth' />
    78. </Chart>
    79. );
    80. }
    81. export default LineChartZoom;
    1. <LineChartZoom dataSource={chartData} />