Dynamically adding AND REMOVING Y Axis

Using ASPNet Core EJ2 Charts

We are adding a second Line series dynamically using this javascript

function addLineSeries(seriesData, axisLabel) {
            var chart = document.getElementById("chart").ej2_instances[0];
            chart.removeSeries(1);

            chart.addAxes([{
                name: 'secondAxis',
                title: axisLabel,
                opposedPosition: true
            }]);

            chart.addSeries([{
                type: 'Line',
                dataSource: seriesData,
                xName: 'Date', 
                yName: 'Value',
                yAxisName: "secondAxis",
                marker: {
                    visible: true,
                    height: 10,
                    width: 10
                }
            }]);
        }

The second series gets added fine as does the Y Axis, however if we call it a second time for a different data set we need to remove the previous dynamic series using chart.removeSeries(1); that works but we are unable to remove the dynamically added second Y Axis. 

How do we remove the second Y Axis? 
Where is the documentation for the EJ2 client side library?

Thanks




1 Reply 1 reply marked as answer

SM Srihari Muthukaruppan Syncfusion Team February 3, 2021 08:23 AM UTC

Hi Pat, 
 
We have analyzed your query. From that, we would like to let you know that we can achieve your requirement by removing axis manually on button click as shown in the below code snippet. Please find the sample, code snippet and screenshot below. 
 
 
Code Snippet: 
document.getElementById("remove").onclick = function () { 
        var chart = document.getElementById("container").ej2_instances[0]; 
         
        if (chart.axisCollections.length > 2) { 
            chart.axisCollections.pop(); 
            chart.axes.pop(); 
        }  
        chart.removeSeries(1); 
    } 
 
Screenshot: 
Add Series: 
 
Remove series And Axis: 
 
 
Let us know if you have any concerns. 
 
Regards, 
Srihari M

Marked as answer
Loader.
Up arrow icon