This is a migrated thread and some comments may be shown as answers.

Remote binding to Pie chart does not work

2 Answers 148 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Werdna
Top achievements
Rank 1
Werdna asked on 12 Jun 2020, 09:24 PM

Hello,

 

I'm using ASP.NET Core 2.1 and trying to get a Pie chart bound to a remote datasource based on this example:  https://demos.telerik.com/aspnet-core/pie-charts/remote-data-binding.  I can't get anything except the "Title" to show. The pie never displays. (FYI, the pie chart works fine for hardcoded data.)  I know the controller works as I'm getting response data in the format I expect.  Here's some streamlined code:

Here's my view:

    @(Html.Kendo().Chart<WT.Models.Cars>()
        .Name("chart1")
.Title(title => title.Text("Title").Position(ChartTitlePosition.Top))
        .DataSource(ds => ds.Read("CarTotals_PieChart", "Output"))
        .Series(series => series.Pie(model => model.NumCars, model => model.CarManu))
        )

Here's my model:

public class Cars
{
    public string CarManu{ get; set; }
    public int NumCars { get; set; }
}

Here's my response JSON data:

{"Data":[{"CarManu":"GM","NumCars":167},{"CarManu":"Ford","NumCars":120},{"CarManu":"Mazda","NumCars":60},{"CarManu":"Ferrari","NumCars":19}],"Total":4,"AggregateResults":null,"Errors":null}

 

I've seen other posts related to this exact same (issue but never a resolution.  What am I doing wrong? Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Silviya Stoyanova
Telerik team
answered on 17 Jun 2020, 11:17 AM

Hello Andrew,

Thank you for the provided snippets!

It seems that the controller returns a DataSourceResult instead of an array.

The chart binds to the data directly, it does not have the knowledge about the structure of the response.

https://docs.telerik.com/aspnet-core/html-helpers/charts/data-binding#remote-data

Try returning the following:

public ActionResult CarTotals_PieChart()
{
          // result is a collection of the models
           var result = new List<Cars>()
           {
               new Cars(){ NumCars= 160, CarMenu = "GM" }
            }
            return Json(result);
}

 

Kind Regards,
Silviya Stoyanova
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Werdna
Top achievements
Rank 1
answered on 17 Jun 2020, 03:25 PM
That was exactly my issue.  It's working now.  Thanks!
Tags
Chart
Asked by
Werdna
Top achievements
Rank 1
Answers by
Silviya Stoyanova
Telerik team
Werdna
Top achievements
Rank 1
Share this question
or