Skip to content

[Feature] Draw a line with the result of brushend event #18536

@inlann

Description

@inlann

What problem does this feature solve?

Hello:

Users can draw any tangent line in the graph based on adding a line graphic with the result of a "brush" event

The following is an example:

// TODO: Initial values should be 0
let xStart = 317;  // These values need to be updated while the brush ends
let xEnd = 576;
let yStart = 123;
let yEnd = 320;

option = {
  xAxis: {
    type: 'value'
  },
  yAxis: {
    type: 'value'
  },
  dataZoom: [
    {
      type: 'inside',
      filterMode: 'none'
    },
    {
      type: 'inside',
      orient: 'vertical',
      filterMode: 'none'
    }
  ],
  brush: {
    toolbox: ['rect', 'clear'],
    brushType: 'rect',
    transformable: false,
    removeOnClick: false
  },
  graphic: [{
    type: 'line',
    shape: {
        x1: xStart,
        y1: yStart,
        x2: xEnd,
        y2: yEnd
    },
    style: {
        lineWidth: 2,
        stroke: 'red'
    }
  }],
  series: [
    {
      data: [
        [1, 150],
        [2, 230],
        [3, 224],
        [4, 218],
        [5, 135],
        [6, 147],
        [7, 260]
      ],
      type: 'line',
      smooth: true,
    }
  ]
};

myChart.on('brushend', (param: any) => {
  console.log(param);
  xStart = param.areas[0].range[0][0]
  xEnd = param.areas[0].range[0][1]
  yStart = param.areas[0].range[1][0]
  yEnd = param.areas[0].range[1][1]
  console.log(xStart, xEnd, yStart, yEnd);
});

Expected results are as follows:

image

** But this example needs to be running in a React application since xStart, xEnd, yStart and yEnd need to be stored in states. **

What does the proposed API look like?

Maybe we could add a drawDiagonalLine to the options for brush like:

  brush: {
    toolbox: ['rect', 'clear'],
    brushType: 'rect',
    transformable: false,
    removeOnClick: false,
    drawDiagonalLine: true  // Default false.
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    enThis issue is in Englishnew-featurependingWe are not sure about whether this is a bug/new feature.staleInactive for a long time. Will be closed in 7 days.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions