Articles in this section
Category / Section

How to bind the JSON data in UWP Chart?

3 mins read

This article explains how to populate the JSON data to UWP Chart with the following steps

 

Step 1: Create the required model in accordance with the JSON data.

 

[JSON Data] - Capacities.json

[
    {
        "Date": "2017-01-01T00:00:00",
        "CapacityUsed": 33.000,
        "CapacityAvailable": 60.000,
        "OverCapacity": 0.0,
        "TotalHours": 60.000
    },
    {
        "Date": "2017-02-05T00:00:00",
        "CapacityUsed": 53.000,
        "CapacityAvailable": 60.000,
        "OverCapacity": 0.0,
        "TotalHours": 60.000
    },
    {
        "Date": "2017-03-05T00:00:00",
        "CapacityUsed": 43.000,
        "CapacityAvailable": 60.000,
        "OverCapacity": 0.0,
        "TotalHours": 60.000
    },
…

 

[C#] Model

public class Model
{
    public DateTime Date { get; set; }
    public decimal CapacityUsed { get; set; }
    public decimal CapacityAvailable { get; set; }
    public decimal OverCapacity { get; set; }
    public decimal TotalHours { get; set; }
}

 

Step 2: Convert JSON data to List<Model>.

 

[C#] ViewModel

public class ViewModel 
{
    public List<Model> Items { get; set; }
 
     public ViewModel()
        {
            
            using (var stream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream("JsonDataBinding.Capacities.json"))
            using (TextReader textStream = new StreamReader(stream))
            {
                var text = textStream.ReadToEnd();
                Items = JsonConvert.DeserializeObject<List<Model>>(text);
            }
        }
}

 

Note:

Build action of Capacities.json should be `Embedded Resource`

Step 3: Bind the converted List<Model> to SfChart.

 

[XAML]

<chart:SfChart Margin="15"  >
    …
    <chart:ColumnSeries XBindingPath="Date"
                        YBindingPath="CapacityUsed"
                        ItemsSource="{Binding Items}" 
                        />
 
</chart:SfChart>

Output

How to bind JSON data to the WPF chart

Conclusion

I hope you enjoyed learning about how to make a UWP Chart with a JSON file in Syncfusion.

You can refer to our UWP Charts feature tour page to know about its other groundbreaking feature representations documentation and how to quickly get started for configuration specifications.  You can also explore our UWP Charts example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied