How to move striplines using keyboard arrow keys in Blazor Charts?
This article explains how to move striplines using keyboard arrow keys in Blazor Charts.
Moving Striplines Using Keyboard Arrow Keys
Blazor Charts provides an option to move the Striplines from one location to another using keyboard events.
This can be achieved by binding the onkeydown and onkeyup events to the chart div container and adjusting the stripline Start and End values in those events.
The code example below demonstrates how to move striplines using keyboard arrow keys.
Index.razor:
@using Syncfusion.Blazor.Charts
<div @onkeydown="KeyDown" @onkeyup="KeyUp">
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category">
<ChartStriplines>
<ChartStripline Start=@start End=@end Color="#EEFFCC" />
</ChartStriplines>
</ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column" DataSource="@WeatherReports" XName="X" YName="Y">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
</div>
@code {
public double start = 2;
public double end = 3;
public void KeyUp(KeyboardEventArgs args)
{
if (args.Key == "ArrowRight")
{
start = start + 1;
end = end + 1;
}
StateHasChanged();
}
public void KeyDown(KeyboardEventArgs args)
{
if (args.Key == "ArrowLeft")
{
start = start - 1;
end = end - 1;
}
StateHasChanged();
}
public class ChartData
{
public string X { get; set; }
public double Y { get; set; }
}
public List<ChartData> WeatherReports = new List<ChartData>
{
new ChartData { X = "Sun", Y = 28 },
new ChartData { X = "Mon", Y = 27 },
new ChartData { X = "Tue", Y = 33 },
new ChartData { X = "Wed", Y = 36 },
new ChartData { X = "Thu", Y = 28 },
new ChartData { X = "Fri", Y = 30 },
new ChartData { X = "Sat", Y = 31 }
};
}
The following screenshot illustrates the output of the code snippet.
Output:
Live Sample for Moving Striplines
Conclusion:
We hope you enjoyed learning how to move striplines using keyboard arrow keys in Blazor Chart component.
You can refer to our Blazor Chart feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor Charts and other Blazor components.
If you have any questions or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!