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

[Bug] Changing series type through setOption does not take effect #19349

Open
hughess opened this issue Dec 1, 2023 · 9 comments
Open

[Bug] Changing series type through setOption does not take effect #19349

hughess opened this issue Dec 1, 2023 · 9 comments
Labels
bug en This issue is in English pending We are not sure about whether this is a bug/new feature.

Comments

@hughess
Copy link

hughess commented Dec 1, 2023

Version

5.4.3

Link to Minimal Reproduction

https://codesandbox.io/s/stacked-horizontal-bar-forked-f7dss4?file=/index.js

Steps to Reproduce

  1. Create a chart
  2. Add another call to setOption after the chart is initialized to change some of the settings
  3. Change something like the series colour - that works
  4. Try changing the series type (e.g., from bar to line)

Current Behavior

When you change attributes of the series, the chart works as expected (e..g, change colour from green to purple).

When you change the series type, the series disappears from the chart. The legend is updated with the correct series type, but the actual chart data is not visible.

Expected Behavior

Should be able to change the series type in the same way you can change the other attributes. Experience should be the same as changing the series type in any of the echarts example pages. E.g., if you go here and change one of these bar series to line it will still work: https://echarts.apache.org/examples/en/editor.html?c=bar-y-category-stack

But if you do the same through a second call to setOption, it will not work

Environment

- OS: Mac
- Browser: N/A
- Framework: N/A

Any additional comments?

I am giving our users a way to override the settings of our chart components by accessing the raw ECharts configuration. I think changing the series type will be a common request. Originally, I was planning to manually merge the settings objects, but was very happy to get it working by letting the user pass their incremental settings to setOption

@hughess hughess added the bug label Dec 1, 2023
@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 Dec 1, 2023
@MatthiasMert
Copy link

MatthiasMert commented Dec 1, 2023

As a worksround you can reapply the data property in setOption and it works as expected: Example

@hughess
Copy link
Author

hughess commented Dec 1, 2023

Ah great, thanks @MatthiasMert !

@hughess
Copy link
Author

hughess commented Dec 1, 2023

Actually this won't work, as our users don't have access to the option object when passing in their options...

@helgasoft
Copy link

@hughess, add option = myChart.getOption(); in the click event.
📌 please close issue if problem solved.

@hughess
Copy link
Author

hughess commented Dec 2, 2023

Here's the situation I'm trying to solve:

Our users will use one of our chart components, like this:

<LineChart 
   data={query}
   x=month
   y=sales
/>

And this new option will let them override the config for echarts like so:

<LineChart 
   data={query}
   x=month
   y=sales
   echartsOptions={{
      series: [
         {type: 'bar'}
      ]
   }}
/>

In the background, I am taking the echartsOptions prop and passing it into setOption() after the initial config is passed.

If the user includes option in their echartsOptions prop it will throw an error that option is undefined. For example, this will throw an error:

<LineChart 
   data={query}
   x=month
   y=sales
   echartsOptions={{
      series: [
         {type: 'bar', data: option.series.data[0]}
      ]
   }}
/>

@helgasoft
Copy link

not-a-bug
looks like a question for a design problem, not an ECharts issue

@hughess
Copy link
Author

hughess commented Dec 2, 2023

Why does data need to be re-supplied when changing series.type? Everything else seems to work without that, which is why I would consider this a bug, or at least an inconsistency in the echarts API

@MatthiasMert
Copy link

If the user includes option in their echartsOptions prop it will throw an error that option is undefined. For example, this will throw an error.

Why should the user include option in the prop? Can you not pass it on his behalf in the background whenever the series type is changed?

@hughess
Copy link
Author

hughess commented Dec 5, 2023

I don't think the user should include option in the prop, but I was also hoping to avoid checking that series.type was passed, since I'll need to get the index for which series they referenced to be able to complete the data update. That approach should work though, so I'll give that a shot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug en This issue is in English pending We are not sure about whether this is a bug/new feature.
Projects
None yet
Development

No branches or pull requests

3 participants