Describe the bug
When a SeriesSpec id is changed, the chart updates with the new spec configurations but the older spec configurations also exist as a separate copy. This is most noticeable when switching data sources; if you switch data sources and also update the spec id, you will see both data sets in the chart.
This is because on componentDidUpdate, we update the series specs by adding the updated spec to chartStore.seriesSpecs with the specId; if no specId changes are involved, the chart will update correctly. But when the specId changes too (see the code example below), then the original spec does not get updated. A first pass basic fix would be to check on update if the specId has changed; if it has, remove the previous spec from map before adding the updated spec with the new specId.
To Reproduce
Steps to reproduce the behavior:
- Add a SeriesSpec w/ a specId (e.g. 'foo')
- Toggle data source & also on toggle, change the specId (e.g. 'bar')
- See that the old data source is still in the chart along with the new one.
Example spec:
const MyChart = () => {
const [isUpdated, update] = useState(false);
return (
<>
<Chart renderer="canvas" className={'story-chart'}>
<LineSeries
id={getSpecId(isUpdated ? 'lines2' : 'lines')}
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Linear}
xAccessor={0}
yAccessors={[1]}
data={
isUpdated
? KIBANA_METRICS.metrics.kibana_os_load[0].data.map(([ts, val]) => [ts, val / 4])
: KIBANA_METRICS.metrics.kibana_os_load[0].data
}
yScaleToDataExtent={false}
/>
</Chart>
<button onClick={() => update(true)}>Update</button>
</>
);
};
Expected behavior
Updated spec should replace previous spec; in this screenshot below, there should only be one line.
Screenshots

Version (please complete the following information):
- OS: Mac 10.14.1 (will affect all OS)
- Browser: Firefox 65.0.1 (will affect all browsers)
- Elastic Charts: v3.8.0
Additional context
Errors in browser console
N/A
Kibana Cross Issues
N/A
Checklist
Describe the bug
When a SeriesSpec id is changed, the chart updates with the new spec configurations but the older spec configurations also exist as a separate copy. This is most noticeable when switching data sources; if you switch data sources and also update the spec id, you will see both data sets in the chart.
This is because on
componentDidUpdate, we update the series specs by adding the updated spec tochartStore.seriesSpecswith the specId; if no specId changes are involved, the chart will update correctly. But when the specId changes too (see the code example below), then the original spec does not get updated. A first pass basic fix would be to check on update if the specId has changed; if it has, remove the previous spec from map before adding the updated spec with the new specId.To Reproduce
Steps to reproduce the behavior:
Example spec:
Expected behavior
Updated spec should replace previous spec; in this screenshot below, there should only be one line.
Screenshots
Version (please complete the following information):
Additional context
Errors in browser console
N/A
Kibana Cross Issues
N/A
Checklist
Kibana Cross Issueslistkibana cross issuetag is associated to the issue if any kibana cross issue is present