https://bizcharts.alibaba-inc.com/product/bizcharts/demo/22

    g2-brush数据下钻折线图
    image.png

    1. let chart;
    2. const scale = {
    3. value: {
    4. alias: '值',
    5. tickCount: 5,
    6. min: 0,
    7. },
    8. date: {
    9. type: 'timeCat',
    10. mask: 'YYYY-MM-DD HH:mm',
    11. tickCount: 8,
    12. nice: false,
    13. },
    14. };
    15. function App() {
    16. useEffect(init, []);
    17. function init() {
    18. new Brush({
    19. chart,
    20. canvas: chart.get('canvas');
    21. style: {
    22. fill: '#ccc',
    23. fillOpacity: 0.3,
    24. },
    25. type: 'X',
    26. onBrushstart() {
    27. chart.hideTooltip();
    28. },
    29. onBrushmove() {
    30. chart.hideTooltip();
    31. },
    32. onBrushend(e) {
    33. const view = chart.get('view');
    34. const {data} = e;
    35. view[1].filterShape(obj => {
    36. return data.indexOf(obj) > -1;
    37. });
    38. }
    39. });
    40. // 双击图表,恢复初始状态
    41. chart.on('plotdbclick', () => {
    42. chart.get('options').filters = {};
    43. chart.repaint();
    44. })
    45. }
    46. }
    47. function onReset() {
    48. chart.get('options').filters = {};
    49. chart.repaint();
    50. }
    51. const attrs = {
    52. data: dataSource,
    53. scale,
    54. height,
    55. padding,
    56. forceFit: true,
    57. onGetInstance: g2Chart => {
    58. g2Chart.animate(false);
    59. chart = g2Chart;
    60. }
    61. }
    62. return (
    63. <Chart {...attrs}>
    64. <Axis name='date' label={label} />
    65. <Axis name='value' />
    66. // 隐藏竖线
    67. <Tooltip crosshairs={false}/>
    68. <Legend />
    69. <Geom
    70. type='line'
    71. position='date*value'
    72. size={2}
    73. shape='smooth'
    74. color='type'
    75. />
    76. </Chart>
    77. )

    g2-brush

    1. function init() {
    2. new Brush({
    3. canvas: chart.get('canvas'),
    4. chart,
    5. type: 'X',
    6. onBrushstart() {
    7. chart.hideTooltip()
    8. },
    9. onBrushmove() {
    10. chart.hideTooltip()
    11. },
    12. })
    13. // 双击清除过滤,恢复初始状态
    14. chart.on('plotdblclick', () => {
    15. chart.get('options').filters = {}
    16. chart.repaint()
    17. })
    18. }