|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Working with data in ##Platform_Name## Chart control | Syncfusion |
| 4 | +description: Learn here all about Working with data in Syncfusion ##Platform_Name## Chart control of Syncfusion Essential JS 2 and more. |
| 5 | +platform: ej2-javascript |
| 6 | +control: Working with data |
| 7 | +publishingplatform: ##Platform_Name## |
| 8 | +documentation: ug |
| 9 | +domainurl: ##DomainURL## |
| 10 | +--- |
| 11 | +<!-- markdownlint-disable MD036 --> |
| 12 | + |
| 13 | +# Working with data in ##Platform_Name## Chart control |
| 14 | + |
| 15 | +Chart can visualize data bound from local or remote data. |
| 16 | + |
| 17 | +## Local data |
| 18 | + |
| 19 | +You can bind a simple JSON data to the chart using [`dataSource`](../api/chart/series/) property in series. Now map the fields in |
| 20 | +JSON to [`xName`](../api/chart/series/#xname-string) and [`yName`](../api/chart/series/#yname-string) properties. |
| 21 | + |
| 22 | +{% if page.publishingplatform == "typescript" %} |
| 23 | + |
| 24 | +{% tabs %} |
| 25 | +{% highlight ts tabtitle="index.ts" %} |
| 26 | +{% include code-snippet/chart/working-with-data-cs1/index.ts %} |
| 27 | +{% endhighlight %} |
| 28 | +{% highlight html tabtitle="index.html" %} |
| 29 | +{% include code-snippet/chart/working-with-data-cs1/index.html %} |
| 30 | +{% endhighlight %} |
| 31 | +{% endtabs %} |
| 32 | + |
| 33 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs1" %} |
| 34 | + |
| 35 | +{% elsif page.publishingplatform == "javascript" %} |
| 36 | + |
| 37 | +{% tabs %} |
| 38 | +{% highlight js tabtitle="index.js" %} |
| 39 | +{% include code-snippet/chart/working-with-data-cs1/index.js %} |
| 40 | +{% endhighlight %} |
| 41 | +{% highlight html tabtitle="index.html" %} |
| 42 | +{% include code-snippet/chart/working-with-data-cs1/index.html %} |
| 43 | +{% endhighlight %} |
| 44 | +{% endtabs %} |
| 45 | + |
| 46 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs1" %} |
| 47 | +{% endif %} |
| 48 | + |
| 49 | +## Remote data |
| 50 | + |
| 51 | +You can also bind remote data to the chart using DataManager. The `DataManager` requires minimal information like webservice URL, adaptor and crossDomain to interact with service endpoint properly. Assign the instance of DataManager to the [`dataSource`](../api/chart/series/#datasource-object---datamanager) property in series and map the fields of data to [`xName`](../api/chart/series/#xname-string) and [`yName`](../api/chart/series/#yname-string) properties. You can also use the [`query`](../api/chart/series/#query-string) property of the series to filter the data. |
| 52 | + |
| 53 | +{% if page.publishingplatform == "typescript" %} |
| 54 | + |
| 55 | +{% tabs %} |
| 56 | +{% highlight ts tabtitle="index.ts" %} |
| 57 | +{% include code-snippet/chart/working-with-data-cs2/index.ts %} |
| 58 | +{% endhighlight %} |
| 59 | +{% highlight html tabtitle="index.html" %} |
| 60 | +{% include code-snippet/chart/working-with-data-cs2/index.html %} |
| 61 | +{% endhighlight %} |
| 62 | +{% endtabs %} |
| 63 | + |
| 64 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs2" %} |
| 65 | + |
| 66 | +{% elsif page.publishingplatform == "javascript" %} |
| 67 | + |
| 68 | +{% tabs %} |
| 69 | +{% highlight js tabtitle="index.js" %} |
| 70 | +{% include code-snippet/chart/working-with-data-cs2/index.js %} |
| 71 | +{% endhighlight %} |
| 72 | +{% highlight html tabtitle="index.html" %} |
| 73 | +{% include code-snippet/chart/working-with-data-cs2/index.html %} |
| 74 | +{% endhighlight %} |
| 75 | +{% endtabs %} |
| 76 | + |
| 77 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs2" %} |
| 78 | +{% endif %} |
| 79 | + |
| 80 | +## Binding data using ODataAdaptor |
| 81 | + |
| 82 | +[`OData`](http://www.odata.org/documentation/odata-version-3-0/) is a standardized protocol for creating and consuming data. You can retrieve data from an OData service using the DataManager. Refer to the following code example for remote data binding using an OData service. |
| 83 | + |
| 84 | +{% if page.publishingplatform == "typescript" %} |
| 85 | + |
| 86 | +{% tabs %} |
| 87 | +{% highlight ts tabtitle="index.ts" %} |
| 88 | +{% include code-snippet/chart/working-with-data-cs3/index.ts %} |
| 89 | +{% endhighlight %} |
| 90 | +{% highlight html tabtitle="index.html" %} |
| 91 | +{% include code-snippet/chart/working-with-data-cs3/index.html %} |
| 92 | +{% endhighlight %} |
| 93 | +{% endtabs %} |
| 94 | + |
| 95 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs3" %} |
| 96 | + |
| 97 | +{% elsif page.publishingplatform == "javascript" %} |
| 98 | + |
| 99 | +{% tabs %} |
| 100 | +{% highlight js tabtitle="index.js" %} |
| 101 | +{% include code-snippet/chart/working-with-data-cs3/index.js %} |
| 102 | +{% endhighlight %} |
| 103 | +{% highlight html tabtitle="index.html" %} |
| 104 | +{% include code-snippet/chart/working-with-data-cs3/index.html %} |
| 105 | +{% endhighlight %} |
| 106 | +{% endtabs %} |
| 107 | + |
| 108 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs3" %} |
| 109 | +{% endif %} |
| 110 | + |
| 111 | +## Binding data using ODataV4Adaptor |
| 112 | + |
| 113 | +ODataV4 is an improved version of the OData protocols, and the `DataManager` can also retrieve and consume ODataV4 services. For more details on ODataV4 services, refer to the [`odata documentation`](http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-os-part1-protocol-complete.html#_Toc453752197). To bind an ODataV4 service, use the **ODataV4Adaptor**. |
| 114 | + |
| 115 | +{% if page.publishingplatform == "typescript" %} |
| 116 | + |
| 117 | +{% tabs %} |
| 118 | +{% highlight ts tabtitle="index.ts" %} |
| 119 | +{% include code-snippet/chart/working-with-data-cs7/index.ts %} |
| 120 | +{% endhighlight %} |
| 121 | +{% highlight html tabtitle="index.html" %} |
| 122 | +{% include code-snippet/chart/working-with-data-cs7/index.html %} |
| 123 | +{% endhighlight %} |
| 124 | +{% endtabs %} |
| 125 | + |
| 126 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs7" %} |
| 127 | + |
| 128 | +{% elsif page.publishingplatform == "javascript" %} |
| 129 | + |
| 130 | +{% tabs %} |
| 131 | +{% highlight js tabtitle="index.js" %} |
| 132 | +{% include code-snippet/chart/working-with-data-cs7/index.js %} |
| 133 | +{% endhighlight %} |
| 134 | +{% highlight html tabtitle="index.html" %} |
| 135 | +{% include code-snippet/chart/working-with-data-cs7/index.html %} |
| 136 | +{% endhighlight %} |
| 137 | +{% endtabs %} |
| 138 | + |
| 139 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs7" %} |
| 140 | +{% endif %} |
| 141 | + |
| 142 | +## Web API adaptor |
| 143 | + |
| 144 | +You can use the **WebApiAdaptor** to bind the chart with a Web API created using an OData endpoint. |
| 145 | + |
| 146 | +{% if page.publishingplatform == "typescript" %} |
| 147 | + |
| 148 | +{% tabs %} |
| 149 | +{% highlight ts tabtitle="index.ts" %} |
| 150 | +{% include code-snippet/chart/working-with-data-cs8/index.ts %} |
| 151 | +{% endhighlight %} |
| 152 | +{% highlight html tabtitle="index.html" %} |
| 153 | +{% include code-snippet/chart/working-with-data-cs8/index.html %} |
| 154 | +{% endhighlight %} |
| 155 | +{% endtabs %} |
| 156 | + |
| 157 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs8" %} |
| 158 | + |
| 159 | +{% elsif page.publishingplatform == "javascript" %} |
| 160 | + |
| 161 | +{% tabs %} |
| 162 | +{% highlight js tabtitle="index.js" %} |
| 163 | +{% include code-snippet/chart/working-with-data-cs8/index.js %} |
| 164 | +{% endhighlight %} |
| 165 | +{% highlight html tabtitle="index.html" %} |
| 166 | +{% include code-snippet/chart/working-with-data-cs8/index.html %} |
| 167 | +{% endhighlight %} |
| 168 | +{% endtabs %} |
| 169 | + |
| 170 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs8" %} |
| 171 | +{% endif %} |
| 172 | + |
| 173 | +The response object should contain the properties **Items** and **Count**, where **Items** represents a collection of entities, and **Count** represents the total number of entities. |
| 174 | + |
| 175 | +The sample response object should appear as follows: |
| 176 | + |
| 177 | +``` |
| 178 | +{ |
| 179 | + Items: [{..}, {..}, {..}, ...], |
| 180 | + Count: 830 |
| 181 | +} |
| 182 | +``` |
| 183 | + |
| 184 | +## Custom adaptor |
| 185 | + |
| 186 | +You can create your own adaptor by extending the built-in adaptors. The following demonstrates the custom adaptor approach and how to add a serial number to the records by overriding the built-in response processing using the **processResponse** method of the **ODataAdaptor**. |
| 187 | + |
| 188 | +{% if page.publishingplatform == "typescript" %} |
| 189 | + |
| 190 | +{% tabs %} |
| 191 | +{% highlight ts tabtitle="index.ts" %} |
| 192 | +{% include code-snippet/chart/working-with-data-cs10/index.ts %} |
| 193 | +{% endhighlight %} |
| 194 | +{% highlight html tabtitle="index.html" %} |
| 195 | +{% include code-snippet/chart/working-with-data-cs10/index.html %} |
| 196 | +{% endhighlight %} |
| 197 | +{% endtabs %} |
| 198 | + |
| 199 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs10" %} |
| 200 | + |
| 201 | +{% elsif page.publishingplatform == "javascript" %} |
| 202 | + |
| 203 | +{% tabs %} |
| 204 | +{% highlight js tabtitle="index.js" %} |
| 205 | +{% include code-snippet/chart/working-with-data-cs10/index.js %} |
| 206 | +{% endhighlight %} |
| 207 | +{% highlight html tabtitle="index.html" %} |
| 208 | +{% include code-snippet/chart/working-with-data-cs10/index.html %} |
| 209 | +{% endhighlight %} |
| 210 | +{% endtabs %} |
| 211 | + |
| 212 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs10" %} |
| 213 | +{% endif %} |
| 214 | + |
| 215 | +## Offline mode |
| 216 | + |
| 217 | +When using remote data binding, all chart actions will be processed on the server-side. To avoid postback for every action, configure the chart to load all data upon initialization and handle actions on the client-side. To enable this behavior, utilize the **offline** property of the `DataManager`. |
| 218 | + |
| 219 | +{% if page.publishingplatform == "typescript" %} |
| 220 | + |
| 221 | +{% tabs %} |
| 222 | +{% highlight ts tabtitle="index.ts" %} |
| 223 | +{% include code-snippet/chart/working-with-data-cs9/index.ts %} |
| 224 | +{% endhighlight %} |
| 225 | +{% highlight html tabtitle="index.html" %} |
| 226 | +{% include code-snippet/chart/working-with-data-cs9/index.html %} |
| 227 | +{% endhighlight %} |
| 228 | +{% endtabs %} |
| 229 | + |
| 230 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs9" %} |
| 231 | + |
| 232 | +{% elsif page.publishingplatform == "javascript" %} |
| 233 | + |
| 234 | +{% tabs %} |
| 235 | +{% highlight js tabtitle="index.js" %} |
| 236 | +{% include code-snippet/chart/working-with-data-cs9/index.js %} |
| 237 | +{% endhighlight %} |
| 238 | +{% highlight html tabtitle="index.html" %} |
| 239 | +{% include code-snippet/chart/working-with-data-cs9/index.html %} |
| 240 | +{% endhighlight %} |
| 241 | +{% endtabs %} |
| 242 | + |
| 243 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs9" %} |
| 244 | +{% endif %} |
| 245 | + |
| 246 | +## Lazy loading |
| 247 | + |
| 248 | +Lazy loading allows you to load data for chart on demand. Chart will fire the scrollEnd event, in that we can get the minimum and maximum range of the axis, based on this, we can upload the data to chart. |
| 249 | + |
| 250 | +{% if page.publishingplatform == "typescript" %} |
| 251 | + |
| 252 | +{% tabs %} |
| 253 | +{% highlight ts tabtitle="index.ts" %} |
| 254 | +{% include code-snippet/chart/working-with-data-cs4/index.ts %} |
| 255 | +{% endhighlight %} |
| 256 | +{% highlight html tabtitle="index.html" %} |
| 257 | +{% include code-snippet/chart/working-with-data-cs4/index.html %} |
| 258 | +{% endhighlight %} |
| 259 | +{% endtabs %} |
| 260 | + |
| 261 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs4" %} |
| 262 | + |
| 263 | +{% elsif page.publishingplatform == "javascript" %} |
| 264 | + |
| 265 | +{% tabs %} |
| 266 | +{% highlight js tabtitle="index.js" %} |
| 267 | +{% include code-snippet/chart/working-with-data-cs4/index.js %} |
| 268 | +{% endhighlight %} |
| 269 | +{% highlight html tabtitle="index.html" %} |
| 270 | +{% include code-snippet/chart/working-with-data-cs4/index.html %} |
| 271 | +{% endhighlight %} |
| 272 | +{% endtabs %} |
| 273 | + |
| 274 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs4" %} |
| 275 | +{% endif %} |
| 276 | + |
| 277 | +## Empty points |
| 278 | + |
| 279 | +The Data points that uses the `null` or `undefined` as value are considered as empty points. Empty data points are ignored and not plotted in the Chart. When the data is provided by using the points property, By using `emptyPointSettings` property in series, you can customize the empty point. Default `mode` of the empty point is `Gap`. |
| 280 | + |
| 281 | +{% if page.publishingplatform == "typescript" %} |
| 282 | + |
| 283 | +{% tabs %} |
| 284 | +{% highlight ts tabtitle="index.ts" %} |
| 285 | +{% include code-snippet/chart/working-with-data-cs5/index.ts %} |
| 286 | +{% endhighlight %} |
| 287 | +{% highlight html tabtitle="index.html" %} |
| 288 | +{% include code-snippet/chart/working-with-data-cs5/index.html %} |
| 289 | +{% endhighlight %} |
| 290 | +{% endtabs %} |
| 291 | + |
| 292 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs5" %} |
| 293 | + |
| 294 | +{% elsif page.publishingplatform == "javascript" %} |
| 295 | + |
| 296 | +{% tabs %} |
| 297 | +{% highlight js tabtitle="index.js" %} |
| 298 | +{% include code-snippet/chart/working-with-data-cs5/index.js %} |
| 299 | +{% endhighlight %} |
| 300 | +{% highlight html tabtitle="index.html" %} |
| 301 | +{% include code-snippet/chart/working-with-data-cs5/index.html %} |
| 302 | +{% endhighlight %} |
| 303 | +{% endtabs %} |
| 304 | + |
| 305 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs5" %} |
| 306 | +{% endif %} |
| 307 | + |
| 308 | +**Customizing empty point** |
| 309 | + |
| 310 | +Specific color for empty point can be set by `fill` property in `emptyPointSettings`. Border for a empty point can be set by `border` property. |
| 311 | + |
| 312 | +{% if page.publishingplatform == "typescript" %} |
| 313 | + |
| 314 | +{% tabs %} |
| 315 | +{% highlight ts tabtitle="index.ts" %} |
| 316 | +{% include code-snippet/chart/working-with-data-cs6/index.ts %} |
| 317 | +{% endhighlight %} |
| 318 | +{% highlight html tabtitle="index.html" %} |
| 319 | +{% include code-snippet/chart/working-with-data-cs6/index.html %} |
| 320 | +{% endhighlight %} |
| 321 | +{% endtabs %} |
| 322 | + |
| 323 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs6" %} |
| 324 | + |
| 325 | +{% elsif page.publishingplatform == "javascript" %} |
| 326 | + |
| 327 | +{% tabs %} |
| 328 | +{% highlight js tabtitle="index.js" %} |
| 329 | +{% include code-snippet/chart/working-with-data-cs6/index.js %} |
| 330 | +{% endhighlight %} |
| 331 | +{% highlight html tabtitle="index.html" %} |
| 332 | +{% include code-snippet/chart/working-with-data-cs6/index.html %} |
| 333 | +{% endhighlight %} |
| 334 | +{% endtabs %} |
| 335 | + |
| 336 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs6" %} |
| 337 | +{% endif %} |
| 338 | + |
| 339 | +## Handling No Data |
| 340 | + |
| 341 | +When no data is available to render in the chart, the `noDataTemplate` property can be used to display a custom layout within the chart area. This layout may include a message indicating the absence of data, a relevant image, or a button to initiate data loading. Styled text, images, or interactive elements can be incorporated to maintain design consistency and improve user guidance. Once data becomes available, the chart automatically updates to display the appropriate visualization. |
| 342 | + |
| 343 | +{% if page.publishingplatform == "typescript" %} |
| 344 | + |
| 345 | +{% tabs %} |
| 346 | +{% highlight ts tabtitle="index.ts" %} |
| 347 | +{% include code-snippet/chart/working-with-data-cs11/index.ts %} |
| 348 | +{% endhighlight %} |
| 349 | +{% highlight html tabtitle="index.html" %} |
| 350 | +{% include code-snippet/chart/working-with-data-cs11/index.html %} |
| 351 | +{% endhighlight %} |
| 352 | +{% endtabs %} |
| 353 | + |
| 354 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs11" %} |
| 355 | + |
| 356 | +{% elsif page.publishingplatform == "javascript" %} |
| 357 | + |
| 358 | +{% tabs %} |
| 359 | +{% highlight js tabtitle="index.js" %} |
| 360 | +{% include code-snippet/chart/working-with-data-cs11/index.js %} |
| 361 | +{% endhighlight %} |
| 362 | +{% highlight html tabtitle="index.html" %} |
| 363 | +{% include code-snippet/chart/working-with-data-cs11/index.html %} |
| 364 | +{% endhighlight %} |
| 365 | +{% endtabs %} |
| 366 | + |
| 367 | +{% previewsample "page.domainurl/code-snippet/chart/working-with-data-cs11" %} |
| 368 | +{% endif %} |
| 369 | + |
0 commit comments