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
close icon

How to set data for chart with JSON from AJAX Request?

I already try this

 <script type="text/javascript" language="javascript">
        $(function () {
            $.ajax({
                dataType: "json",
                url: "/API/Report",
                success: function (revenue) {
                    var chartData = [{ year: revenue.year, total: revenue.total }];
                    $("#container").ejChart({
                        series: [{
                            type: 'line',
                            dataSource: chartData,
                            xName: "year",
                            yName: "total"
                        }] 

                    })
                }
            });
</script>

But not working

1 Reply

BP Baby Palanidurai Syncfusion Team June 6, 2018 03:45 AM UTC

Hi Arif, 

Thanks for using syncfusion products, 

We have analyzed your query and as for your requirement we have prepared a sample. In that sample, we are getting data using ajax, sample is working fine at our end. We have noticed your code snippet, revenue is data collection but you are trying to get revenue.year. So we suspect that is reason for sample is not working. Please find the below code snippet to achieve this requirement, 

$.ajax({ 
            type: "POST", 
            url: "Home/Getjsondata", 
            data: {}, 
            dataType: "json", 
            async: false, 
            success: function (revenue) { 
                var chartData = revenue; 
               //here revenue is a array collection, so i have assigned directly to chart data source. 
                $("#container").ejChart({ 
                    series: [{ 
                        type: 'line', 
                        dataSource: chartData, 
                        xName: "Year", 
                        yName: "Total" 
                    }] 
                }) 
            } 
       }); 

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
Screenshot: 
 
Sample for your reference can be find from the below link, 
  
Kindly revert us, if you have any concerns. 


Thanks, 
Baby 


Loader.
Up arrow icon