Skip to main content
A newer version of this page is available. .

DashboardJsonDataSource Class

A data source that retrieves data stored in JSON format.

Namespace: DevExpress.DashboardCommon

Assembly: DevExpress.Dashboard.v19.2.Core.dll

Declaration

public class DashboardJsonDataSource :
    JsonDataSource,
    IDashboardDataSource,
    IDashboardComponent,
    IComponent,
    IDisposable,
    ISupportInitialize,
    ISupportPrefix,
    IDashboardDataSourceInternal,
    IExternalSchemaConsumer,
    IFederationDataProvider

Remarks

The DashboardJsonDataSource allows you to extract JSON data from a Web-service endpoint URI, text file, or a string in JSON format.

Important

The DashboardJsonDataSource object requires the open source Newtonsoft.Json library. Install the Newtonsoft.Json NuGet package in Visual Studio.

Design Time

To connect to the JSON data source, perform the following steps.

  1. Click the New Data Source button in the Data Source ribbon tab.

    DataBinding_NewDataSource

  2. On the first page of the invoked Data Source Wizard dialog, select JSON data source and click Next. The wizard guides you to specify the JSON data location and select the root node.

Runtime

  1. Instantiate the DashboardJsonDataSource object with a simple constructor.

  2. Use the JsonSource property to specify the JSON data location.

  3. Use the RootElement property to specify a root JSON node.

  4. Call the Fill method to retrieve data.

Note

The complete sample project How to Bind a Dashboard to the JSON Data Source at Runtime is available in the DevExpress Examples repository.

The code sample below illustrates how to retrieve JSON data from the Web.

using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Json;
// ...
public static DashboardJsonDataSource CreateJsonDataSourceFromWeb()
{
    var jsonDataSource = new DashboardJsonDataSource();
    jsonDataSource.JsonSource = new UriJsonSource(new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"));
    jsonDataSource.RootElement = "Customers";
    jsonDataSource.Fill();
    return jsonDataSource;
}

The code sample below illustrates how to use JSON data from a file.

using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Json;
// ...
public static DashboardJsonDataSource CreateJsonDataSourceFromFile()
{
    var jsonDataSource = new DashboardJsonDataSource();
    Uri fileUri = new Uri("customers.json", UriKind.RelativeOrAbsolute);
    jsonDataSource.JsonSource = new UriJsonSource(fileUri);
    jsonDataSource.RootElement = "Customers";
    jsonDataSource.Fill();
    return jsonDataSource;
}

The code sample below illustrates how to use JSON data from a string variable.

using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Json;
// ...
public static DashboardJsonDataSource CreateJsonDataSourceFromString()
{
  var jsonDataSource = new DashboardJsonDataSource();
  string json = "{\"Customers\":[{\"Id\":\"ALFKI\",
  \"CompanyName\":\"Alfreds Futterkiste\",\"ContactName\":\"Maria Anders\",
  \"ContactTitle\":\"Sales Representative\",\"Address\":\"Obere Str. 57\",
  \"City\":\"Berlin\",\"PostalCode\":\"12209\",\"Country\":\"Germany\",
  \"Phone\":\"030-0074321\",\"Fax\":\"030-0076545\"}],\"ResponseStatus\":{}}";
  jsonDataSource.JsonSource = new CustomJsonSource(json);
  jsonDataSource.RootElement = "Customers";
  jsonDataSource.Fill();
  return jsonDataSource;
}

Inheritance

Object
MarshalByRefObject
Component
DevExpress.DataAccess.DataComponentBase
JsonDataSource
DashboardJsonDataSource
See Also