0
votes

im follow the next amcharts : https://www.amcharts.com/demos/simple-column-chart/ to implement in my project, but my question now is how to insert data from database in the "chart.data = [{ "

i already have in controller this :

public JsonResult GetChartData()
        {
            var model = _context.TBL_Objectives_Task
                .ToList()
                .Select(m => new Objectives_TaskModel
                {
                    id= m.id,
                    name= m.name,
                    decimalvalue = m.decimalvalue 
                }).OrderBy(j => j.Pace).ToList();

            return Json(model.ToArray(), JsonRequestBehavior.AllowGet);
        }

and then i want to pass this to the Amcharts

1

1 Answers

1
votes

As per the Amcharts documentation on external data sources, you can set the chart to fetch the data from a URL (instead of using a hard-coded JS array), so you can just set that URL to the correct route to the action method you've shown above. Something like this:

chart.dataSource.url = "YourController/GetChartData";

N.B. Since you're using ASP.NET MVC, if the JS code for your chart is within a Razor view file, you could use the @Url.Action helper to generate the correct URL for you.