Skip to content

Commit ca19774

Browse files
authored
Merge pull request #6755 from syncfusion-content/983838-ChartFeatures3
983838: Updated the UG content and example changes in the chart control.
2 parents ff30bb5 + 2ab53f0 commit ca19774

File tree

10 files changed

+255
-262
lines changed

10 files changed

+255
-262
lines changed

blazor/chart/events.md

Lines changed: 83 additions & 135 deletions
Large diffs are not rendered by default.

blazor/chart/how-to/add-remove.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
33
title: Add or Remove Series in Blazor Charts Component | Syncfusion
4-
description: Checkout and learn here all about Add or Remove Series in Syncfusion Blazor Charts component and more.
4+
description: Learn to dynamically add or remove series in Syncfusion Blazor Charts component to update visualizations based on user input.
55
platform: Blazor
66
control: Chart
77
documentation: ug
@@ -11,13 +11,14 @@ documentation: ug
1111

1212
# Add or Remove Series in Blazor Charts Component
1313

14-
The chart series can be dynamically added or removed by adding and removing a series to the [ChartSeriesCollection](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeriesCollection.html). Follow the steps below to dynamically add or remove a series.
14+
Syncfusion Blazor Charts allow dynamic addition and removal of chart series using the [ChartSeriesCollection](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeriesCollection.html). Follow these steps to update chart series at runtime:
1515

16-
**Step 1:**
16+
## Step 1: Render Series Dynamically
1717

18-
Render a series using [ChartSeriesCollection](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeriesCollection.html) class of the chart.
18+
Render chart series by iterating over a collection mapped to the [ChartSeriesCollection](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeriesCollection.html).
1919

2020
```cshtml
21+
2122
<SfChart>
2223
<ChartSeriesCollection>
2324
@foreach (SeriesData series in SeriesCollection)
@@ -27,22 +28,26 @@ Render a series using [ChartSeriesCollection](https://help.syncfusion.com/cr/bla
2728
}
2829
</ChartSeriesCollection>
2930
</SfChart>
31+
3032
```
3133

32-
**Step 2:**
34+
## Step 2: Add and Remove Controls
3335

34-
Create buttons to call add and remove methods, which will add and remove a series from the chart respectively.
36+
Create buttons to trigger methods for adding or removing series from the chart.
3537

3638
```cshtml
39+
3740
<SfButton @onclick="AddChartSeries">Add Chart Series</SfButton>
3841
<SfButton @onclick="RemoveChartSeries">Remove Chart Series</SfButton>
42+
3943
```
4044

41-
**Step 3:**
45+
## Step 3: Add Series Method
4246

43-
To add a new series to the chart dynamically, use the code below in the **AddChartSeries** method. This code adds a new series data to the series list named **SeriesCollection** mapped to the [ChartSeriesCollection](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeriesCollection.html).
47+
Add a new series to the chart by appending data to the series collection.
4448

4549
```c#
50+
4651
public void AddChartSeries()
4752
{
4853
SeriesCollection.Add(new SeriesData
@@ -52,25 +57,28 @@ public void AddChartSeries()
5257
Data = GetChartData()
5358
});
5459
}
60+
5561
```
5662

57-
**Step 4:**
63+
## Step 4: Remove Series Method
5864

59-
To remove a series from the chart dynamically, use the code below in the **RemoveChartSeries** method. This code removes a series data from the series list named **SeriesCollection** mapped to the [ChartSeriesCollection](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeriesCollection.html).
65+
Remove a series from the chart by deleting the last item in the series collection.
6066

6167
```c#
68+
6269
public void RemoveChartSeries()
6370
{
6471
if (SeriesCollection.Count > 0)
6572
{
6673
SeriesCollection.Remove(SeriesCollection[SeriesCollection.Count - 1]);
6774
}
6875
}
76+
6977
```
7078

71-
**Action:**
79+
## Action
7280

73-
By clicking the **Add Chart Series** button a new series will be added to the chart and similarly by clicking the **Remove Chart Series** button the last series in the chart series collection will be removed from the chart. The complete code snippet for the preceding steps is available below.
81+
Click **Add Chart Series** to insert a new series, or **Remove Chart Series** to delete the last series from the chart. The complete code sample is shown below.
7482

7583
```cshtml
7684
@@ -92,8 +100,7 @@ By clicking the **Add Chart Series** button a new series will be added to the ch
92100
</SfChart>
93101
</div>
94102
95-
@code{
96-
103+
@code {
97104
List<SeriesData> SeriesCollection;
98105
99106
// Here, the chart series has been added by adding series data to the "SeriesCollection" list.
@@ -185,8 +192,8 @@ By clicking the **Add Chart Series** button a new series will be added to the ch
185192
set;
186193
}
187194
}
188-
189195
}
196+
190197
```
191198

192199
N> Refer to our [Blazor Charts](https://www.syncfusion.com/blazor-components/blazor-charts) feature tour page for its groundbreaking feature representations and also explore our [Blazor Chart Example](https://blazor.syncfusion.com/demos/chart/line?theme=bootstrap5) to know various chart types and how to represent time-dependent data, showing trends at equal intervals.

blazor/chart/how-to/axis-hide.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
33
title: Hiding Axis in Blazor Charts Component | Syncfusion
4-
description: Checkout and learn here all about Hiding Axis in Syncfusion Blazor Charts component and much more details.
4+
description: Check out and learn here all about Hiding Axis in Syncfusion Blazor Charts component and much more details.
55
platform: Blazor
66
control: Chart
77
documentation: ug
@@ -11,13 +11,14 @@ documentation: ug
1111

1212
# Hiding Axis in Blazor Charts Component
1313

14-
The axis associated with the series can be hidden by toggling the legend item of the relevant series. Follow the steps below to hide the measure axis associated with the series.
14+
The axis associated with a series can be hidden by toggling the legend item of the relevant series. Follow these steps to hide the measure axis associated with a series.
1515

16-
**Step 1:**
16+
## Step 1: Render Chart Series and Axes
1717

18-
Render a chart with three series and three axis using [ChartSeriesCollection](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeriesCollection.html) and [ChartAxes](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartAxes.html) properties of the chart. Map each series to a measure axis using [YAxisName](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeries.html#Syncfusion_Blazor_Charts_ChartSeries_YAxisName) property of the [ChartSeries](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeries.html).
18+
Render a chart with three series and three axes using [ChartSeriesCollection](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeriesCollection.html) and [ChartAxes](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartAxes.html). Map each series to a measure axis using the [YAxisName](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartSeries.html#Syncfusion_Blazor_Charts_ChartSeries_YAxisName) property.
1919

2020
```cshtml
21+
2122
<SfChart>
2223
<ChartAxes>
2324
<ChartAxis Name="yAxis1" />
@@ -34,25 +35,29 @@ Render a chart with three series and three axis using [ChartSeriesCollection](ht
3435
</ChartSeriesCollection>
3536
3637
</SfChart>
38+
3739
```
3840

39-
**Step 2:**
41+
## Step 2: Configure Legend Settings
4042

41-
In the [ChartLegendSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartLegendSettings.html), configure the [Visible](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartLegendSettings.html#Syncfusion_Blazor_Charts_ChartLegendSettings_Visible) property to display the legend and the [ToggleVisibility](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartLegendSettings.html#Syncfusion_Blazor_Charts_ChartLegendSettings_ToggleVisibility) property to enable legend item toggling to control the visibility of the associated series.
43+
In [ChartLegendSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartLegendSettings.html), set the [Visible](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartLegendSettings.html#Syncfusion_Blazor_Charts_ChartLegendSettings_Visible) property to display the legend and [ToggleVisibility](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartLegendSettings.html#Syncfusion_Blazor_Charts_ChartLegendSettings_ToggleVisibility) to enable legend item toggling.
4244

4345
```cshtml
46+
4447
<SfChart>
4548
...
4649
<ChartLegendSettings Visible="true" ToggleVisibility="true" />
4750
...
4851
</SfChart>
52+
4953
```
5054

51-
**Action:**
55+
## Action
5256

53-
By clicking the legend items, one can now toggle the visibility of the associated series. Once the series has been removed, the associated axis will be removed from the chart. If the legend item is toggled again to show the series, the associated axis with the series will be added to the chart. The complete code snippet for the preceding steps is available below.
57+
Clicking legend items toggles the visibility of the associated series. When a series is hidden, its axis is removed from the chart. Toggling the legend item again restores the series and its axis. The following code demonstrates this behavior.
5458

5559
```cshtml
60+
5661
@using Syncfusion.Blazor.Charts
5762
5863
<SfChart>
@@ -73,7 +78,7 @@ By clicking the legend items, one can now toggle the visibility of the associate
7378
</SfChart>
7479
7580
76-
@code{
81+
@code {
7782
7883
public List<ChartData> DataPoints = new List<ChartData>
7984
{
@@ -93,6 +98,7 @@ By clicking the legend items, one can now toggle the visibility of the associate
9398
}
9499
95100
}
101+
96102
```
97103

98104
N> Refer to our [Blazor Charts](https://www.syncfusion.com/blazor-components/blazor-charts) feature tour page for its groundbreaking feature representations and also explore our [Blazor Chart Example](https://blazor.syncfusion.com/demos/chart/line?theme=bootstrap5) to know various chart types and how to represent time-dependent data, showing trends at equal intervals.

blazor/chart/how-to/dynamic-points.md

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
---
22
layout: post
33
title: Dynamic Points in Blazor Charts Component | Syncfusion
4-
description: Checkout and learn here all about the Dynamic Points in Syncfusion Blazor Charts component and much more.
4+
description: Check out and learn how to add or remove Data Points dynamically in Syncfusion Blazor Charts component.
55
platform: Blazor
66
control: Chart
77
documentation: ug
88
---
99

1010
# Dynamic Points in Blazor Charts Component
1111

12-
We can use chart mouse/touch events to dynamically add or remove points from an existing data source by clicking within the chart area. These events allow us to obtain the location of the current cursor as X and Y values in the event arguments. The point's X and Y values can then be updated with new data from the existing data source. To achieve dynamic points, follow the steps outlined below.
12+
Syncfusion Blazor Charts support dynamic addition and removal of points using mouse or touch events. Users can interactively update the data source by clicking within the chart area. Follow these steps to implement dynamic points:
1313

14-
**Step 1**
14+
## Step 1: Configure ChartMouseClick Event
1515

16-
Add the [ChartMouseClick](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartEvents.html#Syncfusion_Blazor_Charts_ChartEvents_ChartMouseClick) event to the chart and add the event handler to that.
16+
Attach the [ChartMouseClick](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartEvents.html#Syncfusion_Blazor_Charts_ChartEvents_ChartMouseClick) event and its handler to the chart to enable point interaction.
1717

18+
```cshtml
1819
19-
``` cshtml
2020
<SfChart>
21-
<ChartEvents ChartMouseClick="MouseClick"></ChartEvents>
22-
...
21+
<ChartEvents ChartMouseClick="MouseClick"></ChartEvents>
22+
...
2323
<SfChart>
24-
@code{
24+
25+
@code {
2526
public void MouseClick(ChartMouseEventArgs args)
2627
{
2728
2829
}
2930
}
31+
3032
```
3133

32-
**Step 2**
34+
## Step 2: Add Points to Data Source
3335

34-
Fetch the X-axis and Y-axis data of the currently clicked location from the [ChartMouseClick](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartEvents.html#Syncfusion_Blazor_Charts_ChartEvents_ChartMouseClick) event arguments, and then add points to the data source using the `AddToDataSource` method, as shown below.
36+
Retrieve the X and Y values from the event arguments and add new points to the data source.
3537

3638
```cshtml
39+
...
3740
public void MouseClick(ChartMouseEventArgs args)
3841
{
3942
if (args.AxisData.Count > 0)
@@ -48,62 +51,69 @@ public void MouseClick(ChartMouseEventArgs args)
4851
}
4952
}
5053
}
54+
5155
public void AddToDataSource(object xValue, object yValue)
5256
{
5357
MouseClickPoints.Add(new PointData() { X = Convert.ToDouble(xValue, null), Y = Convert.ToDouble(yValue, null) });
5458
}
55-
```
5659
57-
**Step 3**
60+
```
61+
62+
## Step 3: Remove Points from Data Source
5863

59-
To remove a point from the existing chart data source, click on it. To do so, create a method `IsSamePoint` to check whether the point obtained from [ChartMouseClick](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Charts.ChartEvents.html#Syncfusion_Blazor_Charts_ChartEvents_ChartMouseClick) already exists in the data source. If the point exists in the data source, it should be removed.
64+
Determine if the clicked point exists in the data source. If present, remove it; if not, add it as a new point.
6065

61-
```
62-
public void MouseClick(ChartMouseEventArgs args)
66+
```cshtml
67+
68+
public void MouseClick(ChartMouseEventArgs args)
69+
{
70+
...
71+
bool isSamePoint;
72+
if (MouseClickPoints.Count >= 1)
6373
{
64-
...
65-
bool isSamePoint;
66-
if (MouseClickPoints.Count >= 1)
67-
{
68-
index = -1;
69-
isSamePoint = IsSamePoint();
70-
if (isSamePoint && MouseClickPoints.Count >= 1)
71-
{
72-
MouseClickPoints.RemoveAt(index);
73-
}
74-
else if (!isSamePoint)
75-
{
76-
AddToDataSource(xPoint, yPoint);
77-
}
78-
}
79-
...
74+
index = -1;
75+
isSamePoint = IsSamePoint();
76+
if (isSamePoint && MouseClickPoints.Count >= 1)
77+
{
78+
MouseClickPoints.RemoveAt(index);
79+
}
80+
else if (!isSamePoint)
81+
{
82+
AddToDataSource(xPoint, yPoint);
83+
}
8084
}
81-
public bool IsSamePoint()
85+
...
86+
}
87+
88+
public bool IsSamePoint()
89+
{
90+
foreach (PointData item in MouseClickPoints)
8291
{
83-
foreach (PointData item in MouseClickPoints)
92+
index = index + 1;
93+
if (item.X == Convert.ToDouble(xPoint, null) &&
94+
item.Y == Convert.ToDouble(yPoint, null))
8495
{
85-
index = index + 1;
86-
if (item.X == Convert.ToDouble(xPoint, null) &&
87-
item.Y == Convert.ToDouble(yPoint, null))
88-
{
89-
return true;
90-
}
96+
return true;
9197
}
92-
return false;
9398
}
99+
return false;
100+
}
101+
94102
```
95103

96-
**Action**
104+
## Action
97105

98-
The below code snippet illustrates a chart that allows users to add new data and update existing data source by clicking in the chart area. Additionally, clicking on an existing point will remove that data from the existing data source.
106+
Clicking in the chart area adds new points, while clicking on an existing point removes it from the data source. The complete code sample is provided below.
99107

100108
``` cshtml
101109
@using Syncfusion.Blazor
102110
@using Syncfusion.Blazor.Charts
103111
104112
<SfChart @ref="Chart">
105-
<ChartEvents ChartMouseClick="MouseClick"></ChartEvents>
106-
<ChartArea><ChartAreaBorder Width="0"></ChartAreaBorder></ChartArea>
113+
<ChartEvents ChartMouseClick="MouseClick" />
114+
<ChartArea>
115+
<ChartAreaBorder Width="0" />
116+
</ChartArea>
107117
<ChartPrimaryXAxis @ref="XAxis" ValueType="Syncfusion.Blazor.Charts.ValueType.Double" RangePadding="ChartRangePadding.Additional" EdgeLabelPlacement="EdgeLabelPlacement.Shift">
108118
<ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
109119
</ChartPrimaryXAxis>
@@ -118,6 +128,7 @@ The below code snippet illustrates a chart that allows users to add new data and
118128
</ChartSeries>
119129
</ChartSeriesCollection>
120130
</SfChart>
131+
121132
@code {
122133
123134
SfChart? Chart;
@@ -191,6 +202,7 @@ The below code snippet illustrates a chart that allows users to add new data and
191202
new PointData { X= 90, Y= 35 }
192203
};
193204
}
205+
194206
```
195207

196208
![Dynamic Points](../images/dynamic-points.gif)

0 commit comments

Comments
 (0)