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

Create report using JsonDataSource

1 Answer 1861 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 06 Apr 2020, 02:48 PM

Hi, I'm working using Telerik standalone (trial) to create a report, using JsonDataSource.

In my model i have "complex" data, like object arrays. Creating the report the first issue is that all these objects are shown ad System.Object, and i need to use some data for tables (and using bindings solved problem for tables).

The problem is that i need to show charts, and i can't find a way to make it work.

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 09 Apr 2020, 08:22 AM

Hello Marco,

There are two options that I can suggest demonstrated in the attached reports:

Report1:

1) Use the same approach with the Binding. I used the following JSON:

{
  'name':'John',
  'age':30,
  'cars': [
    { 'model':'Ford', 'price': 50 },
    { 'model':'BMW', 'price':42 },
    { 'model':'Fiat', 'price':8 }
  ]
 }

The graph will display the models and their prices. 

1. Аdd a pie chart with:

Series: name

Value: age

2. Remove the DataSource and set the following Binding to the graph:

Property path: DataSource

Expression: =Fields.cars

3. Change "name" with "model" and "age" with "price" in Series and SeriesGroup properties.

 

Report2:

1. Add a separate JSON DataSource with the same JSON but set the DataSelector property:

$['cars']

2. Then add the graph as usual:

Series: model

Value: price

 

Regards,
Neli
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.
peter
Top achievements
Rank 1
commented on 10 Nov 2021, 03:29 PM

i got a nested json and tried the above though it doesnt work, what if the array isnt key value pairs but contains json objects.
ea an array of json objects 
Dimitar
Telerik team
commented on 15 Nov 2021, 09:27 AM

Could you please provide an example of your JSON structure?

Generally, the approaches suggested by Neli are the only available approaches for working with nested JSON.

Besides that, there is the option of using the Item(index,collection) function which returns the element of the collection with the given index (zero-based) but this function is generally meant to be used to get a specific item in the collection rather than listing them all as it expects an index parameter.

peter
Top achievements
Rank 1
commented on 19 Nov 2021, 11:26 AM

i had my data as object with many child objects, now its an array of objects.
both are essentially valid though the later might be more commonly used, and it worked well. you can close this case
Tags
Report Designer (standalone)
Asked by
Marco
Top achievements
Rank 1
Answers by
Neli
Telerik team
Share this question
or