We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add trendline of selected series chart

Thread ID:





148670 Oct 29,2019 09:20 PM UTC Oct 31,2019 06:30 AM UTC ASP.NET MVC 3
Tags: Chart
Maico Schmitz
Asked On October 29, 2019 09:20 PM UTC


How can I add a trendline by selecting a series and clicking a button?

The code I want is something like this:

 AdicionarTendencia(ch) {     var chart = document.getElementById(ch).ej2_instances[0];     var series = chart.selectionModule.selectedDataIndexes;     if (series.length > 0) {         var i = series[0].series;         chart.series[i].trendlines.add();     }     else {         alert("Nenhuma Série Selecionada! Por Favor selecione primeiro uma série.")     } }

Is there a way to do this? Thank you!

Kalaimathi Chellaiah [Syncfusion]
Replied On October 30, 2019 10:43 AM UTC

Hi Maico, 
Greetings from Syncfusion. 
We have analysed your query. Based on that we have prepared a sample. In that, we are adding trendlines after selecting a series and clicking the button. Please find below sample and code snippet, 
Code Snippet: 
  document.getElementById('togglebtn').onclick = () => { 
        var chart = document.getElementById('container').ej2_instances[0]; 
        var series = chart.selectionModule.selectedDataIndexes; 
        if (series.length > 0) { 
            var i = series[0].series; 
            if (i == 0) { 
                chart.series[i].trendlines = [{ type: 'Linear', animation: { enable: false }, fill: 'red', width: 3, dashArray: '5,5' }]; 
               //To maintain the selected data index 
                chart.selectedDataIndexes = [{ series: i }]; 
//other code here 
        } else { 
            alert("Nenhuma Série Selecionada! Por Favor selecione primeiro uma série.") 
Kindly check the above sample and revert us, if you need further assistance. 


Maico Schmitz
Replied On October 30, 2019 02:28 PM UTC

Hi Kalai,

Worked perfectly.

Thank you!

Srihari Muthukaruppan [Syncfusion]
Replied On October 31, 2019 06:30 AM UTC

Hi Maico,  
Most welcome. Kindly get in touch with us, if you would require further assistance. We are always happy in assisting you.   
Srihari M 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon