Skip to content

DOCINFRA-2341_merged_using_automation #3034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 11, 2024
Merged
139 changes: 139 additions & 0 deletions ej2-asp-core-mvc/chart/EJ2_ASP.MVC/dynamic-data-update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
layout: post
title: Dynamic data update in ##Platform_Name## Syncfusion Chart Component
description: Learn here all about dynamic data update in Syncfusion ##Platform_Name## Chart component of Syncfusion Essential JS 2 and more.
platform: ej2-asp-core-mvc
control: Dynamic Data Update
publishingplatform: ##Platform_Name##
documentation: ug
---


# Dynamic data update in ##Platform_Name## Chart Component

## Adding a new data point

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:

* The first parameter is the new data point to add to your existing data source.
* The optional second parameter specifies the animation duration for adding the new data point.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/add-point/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Add-point.cs" %}
{% include code-snippet/chart/dynamic-update/add-point/add-point.cs %}
{% endhighlight %}
{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/add-point/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Add-point.cs" %}
{% include code-snippet/chart/dynamic-update/add-point/add-point.cs %}
{% endhighlight %}
{% endtabs %}
{% endif %}



## Removing an existing data point

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:

* The first parameter is the index of the data point that needs to be removed from the existing data source.
* The optional second parameter specifies the animation duration for removing the data point.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/remove-point/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Remove-point.cs" %}
{% include code-snippet/chart/dynamic-update/remove-point/remove-point.cs %}
{% endhighlight %}
{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/remove-point/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Remove-point.cs" %}
{% include code-snippet/chart/dynamic-update/remove-point/remove-point.cs %}
{% endhighlight %}
{% endtabs %}
{% endif %}



## Replacing entire data points

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:

* The first parameter is the new set of data points to be updated.
* The optional second parameter specifies the animation duration for updating the new data source.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/set-data/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Set-data.cs" %}
{% include code-snippet/chart/dynamic-update/set-data/set-data.cs %}
{% endhighlight %}
{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/set-data/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Set-data.cs" %}
{% include code-snippet/chart/dynamic-update/set-data/set-data.cs %}
{% endhighlight %}
{% endtabs %}
{% endif %}



## Click to add or remove a data point

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.

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.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/click-add-point/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Click-add-point.cs" %}
{% include code-snippet/chart/dynamic-update/click-add-point/click-add-point.cs %}
{% endhighlight %}
{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/click-add-point/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Click-add-point.cs" %}
{% include code-snippet/chart/dynamic-update/click-add-point/click-add-point.cs %}
{% endhighlight %}
{% endtabs %}
{% endif %}


139 changes: 139 additions & 0 deletions ej2-asp-core-mvc/chart/EJ2_ASP.NETCORE/dynamic-data-update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
layout: post
title: Dynamic data update in ##Platform_Name## Syncfusion Chart Component
description: Learn here all about dynamic data update in Syncfusion ##Platform_Name## Chart component of Syncfusion Essential JS 2 and more.
platform: ej2-asp-core-mvc
control: Dynamic Data Update
publishingplatform: ##Platform_Name##
documentation: ug
---


# Dynamic data update in ##Platform_Name## Chart Component

## Adding a new data point

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:

* The first parameter is the new data point to add to your existing data source.
* The optional second parameter specifies the animation duration for adding the new data point.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/add-point/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Add-point.cs" %}
{% include code-snippet/chart/dynamic-update/add-point/add-point.cs %}
{% endhighlight %}
{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/add-point/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Add-point.cs" %}
{% include code-snippet/chart/dynamic-update/add-point/add-point.cs %}
{% endhighlight %}
{% endtabs %}
{% endif %}



## Removing an existing data point

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:

* The first parameter is the index of the data point that needs to be removed from the existing data source.
* The optional second parameter specifies the animation duration for removing the data point.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/remove-point/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Remove-point.cs" %}
{% include code-snippet/chart/dynamic-update/remove-point/remove-point.cs %}
{% endhighlight %}
{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/remove-point/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Remove-point.cs" %}
{% include code-snippet/chart/dynamic-update/remove-point/remove-point.cs %}
{% endhighlight %}
{% endtabs %}
{% endif %}



## Replacing entire data points

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:

* The first parameter is the new set of data points to be updated.
* The optional second parameter specifies the animation duration for updating the new data source.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/set-data/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Set-data.cs" %}
{% include code-snippet/chart/dynamic-update/set-data/set-data.cs %}
{% endhighlight %}
{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/set-data/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Set-data.cs" %}
{% include code-snippet/chart/dynamic-update/set-data/set-data.cs %}
{% endhighlight %}
{% endtabs %}
{% endif %}



## Click to add or remove a data point

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.

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.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/click-add-point/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Click-add-point.cs" %}
{% include code-snippet/chart/dynamic-update/click-add-point/click-add-point.cs %}
{% endhighlight %}
{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/chart/dynamic-update/click-add-point/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Click-add-point.cs" %}
{% include code-snippet/chart/dynamic-update/click-add-point/click-add-point.cs %}
{% endhighlight %}
{% endtabs %}
{% endif %}


Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public ActionResult Index()
{
List<DynamicChartData> chartData = new List<DynamicChartData>
{
new DynamicChartData{ x= "Germany", y= 72 },
new DynamicChartData{ x= "Russia", y= 103.1 },
new DynamicChartData{ x= "Brazil", y= 139.1 },
new DynamicChartData{ x= "India", y= 462.1 },
new DynamicChartData{ x= "China", y= 721.4 },
new DynamicChartData{ x= "USA", y= 286.9 },
new DynamicChartData{ x= "Great Britain", y= 115.1 },
new DynamicChartData{ x= "Nigeria", y= 97.2 }
};
ViewBag.dataSource = chartData;
return View();
}
public class DynamicChartData
{
public string x;
public double y;
}
26 changes: 26 additions & 0 deletions ej2-asp-core-mvc/code-snippet/chart/dynamic-update/add-point/razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Spline).
XName("x").
YName("y").
Name("Users").
Width(2).
Marker(mr => mr.Visible(true).DataLabel(dl => dl.Visible(true).Position(Syncfusion.EJ2.Charts.LabelPosition.Top)
.Font(font => font.FontWeight("600"))))
DataSource(ViewBag.dataSource).
Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category).EnableTrim(false).MajorGridLines(mg => mg.Width(0)).MajorTickLines(mt => mt.Width(0))
).PrimaryYAxis(py => py.Minimum(0).Maximum(800).LabelFormat("{value}M").EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
).Title("Internet Users - 2016").LegendSettings(leg => leg.Visible(false)
).ChartArea(area => area.Border(br => br.Width(1))).Render()

<div>
@Html.EJS().Button("add").IsPrimary(true).Content("Add Point").Render()
</div>
<script>
document.getElementById('add').onclick = () => {
var chart = document.getElementById('container').ej2_instances[0];
chart.series[0].addPoint({ x: "Japan", y: 118.2 });
}
</script>

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<ejs-chart id="container" title="Internet Users - 2016">
<e-chart-primaryxaxis valueType="@Syncfusion.EJ2.Charts.ValueType.Category" enableTrim="false">
<e-majorgridlines width="0"></e-majorgridlines>
<e-majorticklines width="0"></e-majorticklines>
</e-chart-primaryxaxis>
<e-chart-primaryyaxis minimum="0" maximum="800" labelFormat="{value}M" edgeLabelPlacement="@Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift">
</e-chart-primaryyaxis>
<e-chart-chartarea>
<e-chartarea-border width="1"></e-chartarea-border>
</e-chart-chartarea>
<e-chart-legendsettings visible="false">
</e-chart-legendsettings>
<e-series-collection>
<e-series dataSource="ViewBag.dataSource" xName="x" yName="y" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Spline" width="2" name="Users">
<e-series-marker visible="true">
<e-series-datalabel visible="true" position="@Syncfusion.EJ2.Charts.LabelPosition.Top">
<e-font fontWeight="600"></e-font>
</e-series-datalabel>
</e-series-marker>
</e-series>
</e-series-collection>
</ejs-chart>

<div>
<ejs-button id="add" content="Add Point" isPrimary="true"></ejs-button>
</div>
<script>
document.getElementById('add').onclick = () => {
var chart = document.getElementById('container').ej2_instances[0];
chart.series[0].addPoint({ x: "Japan", y: 118.2 });
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public ActionResult Index()
{
List<DynamicChartData> chartData = new List<DynamicChartData>
{
new DynamicChartData { x = 20, y = 20 },
new DynamicChartData { x = 80, y = 80 }
};
ViewBag.dataSource = chartData;
return View();
}
public class DynamicChartData
{
public double x;
public double y;
}
Loading