|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Dynamic data update in ##Platform_Name## Syncfusion Chart Component |
| 4 | +description: Learn here all about dynamic data update in Syncfusion ##Platform_Name## Chart component of Syncfusion Essential JS 2 and more. |
| 5 | +platform: ej2-asp-core-mvc |
| 6 | +control: Dynamic Data Update |
| 7 | +publishingplatform: ##Platform_Name## |
| 8 | +documentation: ug |
| 9 | +--- |
| 10 | + |
| 11 | + |
| 12 | +# Dynamic data update in ##Platform_Name## Chart Component |
| 13 | + |
| 14 | +## Adding a new data point |
| 15 | + |
| 16 | +The `AddPoint` method is used to dynamically add a new data point to the chart series. This method is particularly useful when you want to update the chart with a new data point without having to refresh the entire chart. This method takes two parameters: |
| 17 | + |
| 18 | +* The first parameter is the new data point to add to your existing data source. |
| 19 | +* The optional second parameter specifies the animation duration for adding the new data point. |
| 20 | + |
| 21 | +{% if page.publishingplatform == "aspnet-core" %} |
| 22 | + |
| 23 | +{% tabs %} |
| 24 | +{% highlight cshtml tabtitle="CSHTML" %} |
| 25 | +{% include code-snippet/chart/dynamic-update/add-point/tagHelper %} |
| 26 | +{% endhighlight %} |
| 27 | +{% highlight c# tabtitle="Add-point.cs" %} |
| 28 | +{% include code-snippet/chart/dynamic-update/add-point/add-point.cs %} |
| 29 | +{% endhighlight %} |
| 30 | +{% endtabs %} |
| 31 | + |
| 32 | +{% elsif page.publishingplatform == "aspnet-mvc" %} |
| 33 | + |
| 34 | +{% tabs %} |
| 35 | +{% highlight razor tabtitle="CSHTML" %} |
| 36 | +{% include code-snippet/chart/dynamic-update/add-point/razor %} |
| 37 | +{% endhighlight %} |
| 38 | +{% highlight c# tabtitle="Add-point.cs" %} |
| 39 | +{% include code-snippet/chart/dynamic-update/add-point/add-point.cs %} |
| 40 | +{% endhighlight %} |
| 41 | +{% endtabs %} |
| 42 | +{% endif %} |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +## Removing an existing data point |
| 47 | + |
| 48 | +The `RemovePoint` method is used to dynamically remove a data point from the chart series. This method is particularly useful when you want to update the chart by removing an existing data point without having to refresh the entire chart. This method takes two parameters: |
| 49 | + |
| 50 | +* The first parameter is the index of the data point that needs to be removed from the existing data source. |
| 51 | +* The optional second parameter specifies the animation duration for removing the data point. |
| 52 | + |
| 53 | +{% if page.publishingplatform == "aspnet-core" %} |
| 54 | + |
| 55 | +{% tabs %} |
| 56 | +{% highlight cshtml tabtitle="CSHTML" %} |
| 57 | +{% include code-snippet/chart/dynamic-update/remove-point/tagHelper %} |
| 58 | +{% endhighlight %} |
| 59 | +{% highlight c# tabtitle="Remove-point.cs" %} |
| 60 | +{% include code-snippet/chart/dynamic-update/remove-point/remove-point.cs %} |
| 61 | +{% endhighlight %} |
| 62 | +{% endtabs %} |
| 63 | + |
| 64 | +{% elsif page.publishingplatform == "aspnet-mvc" %} |
| 65 | + |
| 66 | +{% tabs %} |
| 67 | +{% highlight razor tabtitle="CSHTML" %} |
| 68 | +{% include code-snippet/chart/dynamic-update/remove-point/razor %} |
| 69 | +{% endhighlight %} |
| 70 | +{% highlight c# tabtitle="Remove-point.cs" %} |
| 71 | +{% include code-snippet/chart/dynamic-update/remove-point/remove-point.cs %} |
| 72 | +{% endhighlight %} |
| 73 | +{% endtabs %} |
| 74 | +{% endif %} |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +## Replacing entire data points |
| 79 | + |
| 80 | +To replace the existing data source in the chart with a new data source, you can simply use the `SetData` method. This method allows you to replace the existing data points in the chart series with a new set of data points, enabling you to easily update the chart with new information. This method takes two parameters: |
| 81 | + |
| 82 | +* The first parameter is the new set of data points to be updated. |
| 83 | +* The optional second parameter specifies the animation duration for updating the new data source. |
| 84 | + |
| 85 | +{% if page.publishingplatform == "aspnet-core" %} |
| 86 | + |
| 87 | +{% tabs %} |
| 88 | +{% highlight cshtml tabtitle="CSHTML" %} |
| 89 | +{% include code-snippet/chart/dynamic-update/set-data/tagHelper %} |
| 90 | +{% endhighlight %} |
| 91 | +{% highlight c# tabtitle="Set-data.cs" %} |
| 92 | +{% include code-snippet/chart/dynamic-update/set-data/set-data.cs %} |
| 93 | +{% endhighlight %} |
| 94 | +{% endtabs %} |
| 95 | + |
| 96 | +{% elsif page.publishingplatform == "aspnet-mvc" %} |
| 97 | + |
| 98 | +{% tabs %} |
| 99 | +{% highlight razor tabtitle="CSHTML" %} |
| 100 | +{% include code-snippet/chart/dynamic-update/set-data/razor %} |
| 101 | +{% endhighlight %} |
| 102 | +{% highlight c# tabtitle="Set-data.cs" %} |
| 103 | +{% include code-snippet/chart/dynamic-update/set-data/set-data.cs %} |
| 104 | +{% endhighlight %} |
| 105 | +{% endtabs %} |
| 106 | +{% endif %} |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | +## Click to add or remove a data point |
| 111 | + |
| 112 | +You can use mouse or touch events to dynamically add or remove data points from an existing data source by clicking on the appropriate position within the chart area. To add a new data point to the existing data source, click anywhere in the chart area, retrieve the x-axis and y-axis information of the clicked location from the `ChartMouseClick` event arguments. Then, utilize the `AddPoint` method to add a new data point to the existing data source. |
| 113 | + |
| 114 | +To remove a data point from the existing data source, simply click on the desired data point. To achieve this, first, verify whether the clicked data point obtained from `ChartMouseClick` already exists in the data source. If it does, remove it by utilizing the `RemovePoint` method based on its index. |
| 115 | + |
| 116 | +{% if page.publishingplatform == "aspnet-core" %} |
| 117 | + |
| 118 | +{% tabs %} |
| 119 | +{% highlight cshtml tabtitle="CSHTML" %} |
| 120 | +{% include code-snippet/chart/dynamic-update/click-add-point/tagHelper %} |
| 121 | +{% endhighlight %} |
| 122 | +{% highlight c# tabtitle="Click-add-point.cs" %} |
| 123 | +{% include code-snippet/chart/dynamic-update/click-add-point/click-add-point.cs %} |
| 124 | +{% endhighlight %} |
| 125 | +{% endtabs %} |
| 126 | + |
| 127 | +{% elsif page.publishingplatform == "aspnet-mvc" %} |
| 128 | + |
| 129 | +{% tabs %} |
| 130 | +{% highlight razor tabtitle="CSHTML" %} |
| 131 | +{% include code-snippet/chart/dynamic-update/click-add-point/razor %} |
| 132 | +{% endhighlight %} |
| 133 | +{% highlight c# tabtitle="Click-add-point.cs" %} |
| 134 | +{% include code-snippet/chart/dynamic-update/click-add-point/click-add-point.cs %} |
| 135 | +{% endhighlight %} |
| 136 | +{% endtabs %} |
| 137 | +{% endif %} |
| 138 | + |
| 139 | + |
0 commit comments