Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] How to obtain the pixel point at the center of the highest point of each grouping column #19934

Open
rr210 opened this issue May 14, 2024 · 3 comments
Labels
en This issue is in English support waiting-for: author

Comments

@rr210
Copy link

rr210 commented May 14, 2024

What problem does this feature solve?

我想要拿到每一个分组柱状图的最高点的中心点, 打算拿graphic实现 现在拿不到每一组最高点的x,y的坐标像素点 想要加标签

What does the proposed API look like?

option = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    }
  },
  legend: {},
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  xAxis: [
    {
        "type": "category",
        "position": "bottom",
        "data": [
            "Alipay+",
            "",
            ""
        ],
        "axisLabel": {
            "color": "#ffffff",
            "fontSize": 12,
            "lineHeight": 16
        }
    },
    {
        "type": "category",
        "position": "bottom",
        "data": [
            "",
            "WF",
            ""
        ],
        "axisLabel": {
            "color": "#ffffff",
            "fontSize": 12,
            "lineHeight": 16
        }
    },
    {
        "type": "category",
        "position": "bottom",
        "data": [
            "",
            "",
            "HK Biz"
        ],
        "axisLabel": {
            "color": "#ffffff",
            "fontSize": 12,
            "lineHeight": 16
        }
    }
],
  yAxis: [
    {
      type: 'value'
    }
  ],
  series:[
    {
        "name": "USD",
        "type": "bar",
        "barWidth": 22,
        "xAxisIndex": 0,
        "data": [
            1000000000015.99
        ]
    },
    {
        "name": "USD",
        "type": "bar",
        "barWidth": 22,
        "xAxisIndex": 1,
        "data": [
            "",
            999999999999.99
        ]
    },
    {
        "name": "USD",
        "type": "bar",
        "barWidth": 22,
        "xAxisIndex": 2,
        "data": [
            "",
            "",
            999999999999.99
        ]
    },
    {
        "name": "EUR",
        "type": "bar",
        "barWidth": 22,
        "xAxisIndex": 0,
        "data": [
            1080699999999.91
        ]
    },
    {
        "name": "CNY",
        "type": "bar",
        "barWidth": 22,
        "xAxisIndex": 1,
        "data": [
            "",
            1408400000000
        ]
    },
    {
        "name": "CNY",
        "type": "bar",
        "barWidth": 22,
        "xAxisIndex": 2,
        "data": [
            "",
            "",
            1408400000000
        ]
    },
    {
        "name": "Others(US $)",
        "type": "bar",
        "barWidth": 22,
        "xAxisIndex": 1,
        "data": [
            "",
            2115000000000
        ]
    }
]
};
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels May 14, 2024
@rr210
Copy link
Author

rr210 commented May 14, 2024

尝试了convertToPixel方法 拿不到返回为NaN

// 假设 myChart 是您的 ECharts 实例
// 您需要等待 chart 完成渲染
myChart.on('finished', function () {
    
    // 假设我们要获取第二个 X 轴(xAxisIndex: 1)第二个柱子(dataIndex: 1)的顶点坐标
    var xAxisIndex = 1;
    var dataIndex = 1;
    var series = myChart.getOption().series;
    var seriesUsingXAxisIndex = series.filter(function(serie) {
      return serie.xAxisIndex === xAxisIndex;
    });

    // 找到最高柱子顶部的像素坐标
    var highestBarPixelCoord = null;
    var highestYValue = 0;
    
    seriesUsingXAxisIndex.forEach(function(serie, index) {
        var barTopValue = serie.data[dataIndex];
        if(barTopValue > highestYValue) {
            highestYValue = barTopValue;
            // 柱子顶部的像素坐标
            highestBarPixelCoord = myChart.convertToPixel({
                seriesIndex: serie.seriesIndex  // 或者使用 seriesId
            }, [dataIndex, barTopValue]);
        }
    });

    if (highestBarPixelCoord) {
        console.log('Highest bar pixel coordinates:', highestBarPixelCoord);
    } else {
        console.error('Failed to convert data point to pixel coordinate');
    }
});

@rr210
Copy link
Author

rr210 commented May 14, 2024

image 拿中心像素点 放标签

@Ovilia
Copy link
Contributor

Ovilia commented May 16, 2024

I tried this and can get the pixels position correctly:

myChart.convertToPixel(
    {
      seriesIndex: 0
    },
    ['Alipay+', 1000000000015.99]
  )

@Ovilia Ovilia added support waiting-for: author and removed new-feature pending We are not sure about whether this is a bug/new feature. labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
en This issue is in English support waiting-for: author
Projects
None yet
Development

No branches or pull requests

2 participants