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] Get calculated max/min value of yaxis #17021

Closed
sammuell opened this issue May 12, 2022 · 10 comments · Fixed by #17098
Closed

[Feature] Get calculated max/min value of yaxis #17021

sammuell opened this issue May 12, 2022 · 10 comments · Fixed by #17098
Labels
en This issue is in English new-feature pending We are not sure about whether this is a bug/new feature. waiting-for: community

Comments

@sammuell
Copy link

What problem does this feature solve?

I would like to retrieve the automatically calculated min/max value of an yaxis.

What does the proposed API look like?

I'm unsure about this. There seems to be no getter API except for chart.getOption(). Using this seems like a hack as the option property would only be readable but not writable using setOption().
option.yAxis[1].minCalculated

@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. waiting-for: community labels May 12, 2022
@jiawulin001
Copy link
Member

As is designed, axis scale will automatically fit the user data so users won't worry about adjusting axis. What effect are you trying to attain?

@sammuell
Copy link
Author

sammuell commented May 14, 2022

Here's my use case:
To highlight the weekend days for better readability of the chart I insert a fake bar chart in light gray (see image below). The height is determined before rendering by the max value of the data (right axis). However, the calculated max value of the yAxis is larger, making the weekend day bar look weird, because it's not at full height of the axis. I would like to get the max value of the axis after rendering and increase the data of the weekend bar to that value.

grafik

@jiawulin001
Copy link
Member

Do you mind providing a similar option to test with? Also, do you mean that you want all gray bars to be at 250 in this picture?

@sammuell
Copy link
Author

sammuell commented May 15, 2022

Also, do you mean that you want all gray bars to be at 250 in this picture?

Exactly. I first tried to draw the grey rectangles using the graphic option. That does not work due to the unknown specific coordinates.

@jiawulin001
Copy link
Member

You can use markArea to achieve such effect, by setting the gray zone data to none and put markArea there. But this method is only applicable to static chart. Please check the sample for reference.

Code Sample
option = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [120, 200, 150, , 70, 110, 130],
      type: 'bar',
      markArea: {
        itemStyle: {
          color: 'rgba(0,0,0,0.1)'
        },
        data: [
          [
            {
              name: 'GrayZone',
              x: '44.5%'
            },
            {
              x: '55.7%'
            }
          ]
        ]
      }
    }
  ]
};

@Ovilia
Copy link
Contributor

Ovilia commented May 16, 2022

markArea is a simpler way to make it. Otherwise, you can use chart.getOptions().grid.height to get the size of the grid area.

@sammuell
Copy link
Author

sammuell commented May 17, 2022

Thanks for pointing me to markArea.
I implemented it using two xAxis properties. However, the rendered result does not extend as far as expected (purple lines)
It seems to work nicely for line charts using xAxis.boundaryGap: false. However, bar charts uses a category xAxis.
grafik


There seems to be an error in the documentation: markArea.data is supposed to be an array, not an object.
https://echarts.apache.org/en/option.html#series-bar.markArea.data

// Taken from https://echarts.apache.org/examples/en/editor.html?c=line-sections
// works:
data: [
  [
    {
      name: 'Morning Peak',
      xAxis: '07:30'
    },
    {
      xAxis: '10:00'
    }
  ]
]

// produces an error:
data: [
  {
    name: 'Morning Peak',
    xAxis: '07:30'
  },
  {
    xAxis: '10:00'
  }
]

@sammuell
Copy link
Author

Otherwise, you can use chart.getOptions().grid.height to get the size of the grid area.

That does not work either: the height is undefined:

console.log(opt.grid[0]);

grafik

@jiawulin001
Copy link
Member

However, bar charts uses a category xAxis.

Right, so you might have to use position relative to DOM to locate the gray bar like what I did in the code sample here

@sammuell
Copy link
Author

The issue at hand is that the chart is a non-static time line. The number of items of the xaxis is changing over time, so you cannot determine the necessary percentages.

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 new-feature pending We are not sure about whether this is a bug/new feature. waiting-for: community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@Ovilia @sammuell @jiawulin001 and others