echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Need x,y,Width,Height of the chart elements

Open RavalikaP opened this issue 3 years ago • 6 comments

What problem does this feature solve?

Need X, Y position along with Height and Weight of the chart elements like xAxis, yAxis, Grid, Legends. If we get this values we will append some graphic elements to it and apply some styling to it.

What does the proposed API look like?

image image

RavalikaP avatar Feb 09 '22 04:02 RavalikaP

There are no such APIs but you can get this information option.grid and option.legend from your input option.

Ovilia avatar Feb 10 '22 02:02 Ovilia

@Ovilia but on option.legend and option.grid we are not getting the updated values. If it is updated then it will be easy to get it.

RavalikaP avatar Feb 10 '22 04:02 RavalikaP

You may get such information via some internal APIs. Just FYI.

Grid

// if there are multiple grids, use `getComponent('grid', gridIndex)`
const gridRect = chart.getModel().getComponent('grid').coordinateSystem.getRect();

Axis

// if there are multiple axes, use `getComponent('xAxis', axisIndex)`
const xAxisModel = chart.getModel().getComponent('xAxis');
const xAxisView = chart.getViewOfComponentModel(xAxisModel);
const xAxisRect = xAxisView.group.getBoundingRect();

plainheart avatar Feb 10 '22 05:02 plainheart

@plainheart , Thank you for the reply. can u please suggest me how to get the legends?

RavalikaP avatar Feb 10 '22 06:02 RavalikaP

@RavalikaP It's similar to the above.

const legendModel = chart.getModel().getComponent('legend');
const legendView = chart.getViewOfComponentModel(legendModel);
const legendRect = legendView.group.getBoundingRect();
const [x, y] = legendView.group.transformCoordToGlobal(legendRect.x, legendRect.y);
const { width, height } = legendRect;
console.log(x, y, width, height);

plainheart avatar Feb 10 '22 07:02 plainheart

This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 7 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.

github-actions[bot] avatar Feb 18 '24 21:02 github-actions[bot]

This issue has been automatically closed because it did not have recent activity. If this remains to be a problem with the latest version of Apache ECharts, please open a new issue and link this to it. Thanks!

github-actions[bot] avatar Feb 25 '24 21:02 github-actions[bot]