Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
How to change width and height of graphic 'rect' programmatically in Echarts (by implementing onClick event or make it resizable by dragging)

I'm using latest echarts and trying to put a rectangle on the canvas using graphic option. We can set width and height of type: 'rect' by using Shape.width and Shape.height according to this documentation.

What I want to do is that I want to change that width and height of rectangle

  1. by clicking on it (by implementing onClick event)
  2. by dragging like in css 'resize' property to a div. Is this possible in echarts?

Here is the sample option code that I'm currently trying to implement. You can use it by replacing it here. The setter function setWidth() can change the value of width variable but Shape.width will not call getWidth() function again. There will not be a new render happening.

let width = 100;

function getWidth() {
  return width;
}

function setWidth(value) {
  width = value;
}

option = {
  graphic: {
    elements: [
      {
        type: 'rect',
        draggable: true,
        shape: {
          x: 0,
          y: 0,
          width: getWidth(),
          height: 100
        },
        style: {
          fill: 'red'
        },
        onclick: function(e) {
          setWidth(400)
        }
      }
    ],
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    }
  }
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Echarts options are usually not dynamic. Which means that if you change any option, you'll have to call yourChartName.setOption(option) (doc).

function setWidth(value) {
  option.graphic.elements[0].shape.width=value;
  myChart.setOption(option);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!