-
Notifications
You must be signed in to change notification settings - Fork 79
docs(charts): add kb for drawing horizontal and vertical lines #1747
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
xristianstefanov
merged 2 commits into
master
from
docs-charts-kb-horizontal-vertical-lines
Nov 14, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
--- | ||
title: Draw Horizontal and Vertical Lines in a Blazor Chart | ||
description: How to draw horizontal and vertical lines in Charts. Draw vertical lines in Charts with line series. Draw horizontal lines in Charts with plot bands. | ||
type: how-to | ||
page_title: How to Draw Horizontal and Vertical Lines in Charts | ||
slug: chart-kb-draw-horizontal-and-vertical-lines | ||
position: | ||
tags: telerik, blazor, chart, draw, horizontal, vertical, lines | ||
ticketid: 1511761, 1569732 | ||
res_type: kb | ||
--- | ||
|
||
## Environment | ||
|
||
<table> | ||
<tbody> | ||
<tr> | ||
<td>Product</td> | ||
<td>Charts for Blazor</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
|
||
## Description | ||
|
||
This KB article answers the following questions: | ||
|
||
* How to draw horizontal and vertical lines in Telerik Blazor Charts? | ||
* How to put pins or markers in Telerik Blazor Charts? | ||
* Is it possible to add limits or thresholds on the Telerik Blazor Chart? | ||
|
||
## Solution | ||
|
||
To configure the Chart for drawing horizontal and vertical lines, you can use [plot bands]({%slug chart-plot-bands%}) or additional [line series]({%slug components/chart/types/line%}). | ||
|
||
### Using Plot Bands | ||
|
||
Steps for drawing vertical and horizontal lines with [plot bands]({%slug chart-plot-bands%}): | ||
|
||
1. Add `PlotBand` instances inside the `PlotBands` collection of a Chart axis. | ||
2. Provide a valid CSS color to the `Color` parameter. | ||
3. [Set the `From` and `To`]({%slug chart-plot-bands%}#setting-from-and-to) plot band parameters. | ||
|
||
>caption Drawing Horizontal and Vertical lines with Plot Bands | ||
|
||
`````CSHTML | ||
<TelerikChart> | ||
<ChartTitle Text="Unrecoverable Errors Per Minute vs. Signal Level"></ChartTitle> | ||
|
||
<ChartSeriesItems> | ||
<ChartSeries Type="ChartSeriesType.Scatter" | ||
Data="@SeriesData" | ||
Name="APSK modulation" | ||
XField="@nameof(ModelData.Strength)" | ||
YField="@nameof(ModelData.Errors)"> | ||
</ChartSeries> | ||
</ChartSeriesItems> | ||
|
||
<ChartXAxes> | ||
<ChartXAxis Max="-30" AxisCrossingValue="@(new object[] { -100 })"> | ||
<ChartXAxisTitle Text="Signal Strength, dBm"></ChartXAxisTitle> | ||
<ChartXAxisPlotBands> | ||
<ChartXAxisPlotBand From="-89.7" To="-89.5" Color="blue" /> | ||
<ChartXAxisPlotBand From="-50" To="-49.5" Color="orange" /> | ||
</ChartXAxisPlotBands> | ||
</ChartXAxis> | ||
</ChartXAxes> | ||
|
||
<ChartYAxes> | ||
<ChartYAxis Max="20"> | ||
<ChartYAxisTitle Text="Error count"></ChartYAxisTitle> | ||
<ChartYAxisPlotBands> | ||
<ChartYAxisPlotBand From="1.5" To="1.7" Color="green"></ChartYAxisPlotBand> | ||
<ChartYAxisPlotBand From="18.5" To="18.6" Color="red"></ChartYAxisPlotBand> | ||
</ChartYAxisPlotBands> | ||
</ChartYAxis> | ||
</ChartYAxes> | ||
</TelerikChart> | ||
|
||
@code { | ||
#region PlotBandsData | ||
private List<ModelData> SeriesData { get; set; } | ||
|
||
protected override void OnInitialized() | ||
{ | ||
SeriesData = new List<ModelData>(); | ||
|
||
var rnd = new Random(); | ||
|
||
for (int i = 0; i < 60; i++) | ||
{ | ||
SeriesData.Add(new ModelData | ||
{ | ||
Strength = rnd.Next(-90 + i / 3, -90 + i), | ||
Errors = rnd.Next(i / 20, i / 3) | ||
}); | ||
} | ||
|
||
base.OnInitialized(); | ||
} | ||
|
||
public class ModelData | ||
{ | ||
public double Strength { get; set; } | ||
public double Errors { get; set; } | ||
} | ||
#endregion | ||
} | ||
````` | ||
|
||
### Using Additional Line Series | ||
|
||
Steps for drawing horizontal and vertical lines with additional [Lines Series]({%slug components/chart/types/line%}): | ||
|
||
1. Add `ChartSeries` instances of type `ChartSeriesType.Line` based on the needed number of lines. | ||
2. Set data for the lines based on the information shown from the main Chart. | ||
|
||
>caption Drawing Horizontal and Vertical lines with additional Lines Chart | ||
|
||
````CSHTML | ||
<TelerikChart> | ||
<ChartSeriesItems> | ||
<ChartSeries Type="ChartSeriesType.Column" Name="Column 1" Data="@firstColumnTypeData"> | ||
</ChartSeries> | ||
<ChartSeries Type="ChartSeriesType.Column" Name="Column 2" Data="@secondColumnTypeData"> | ||
</ChartSeries> | ||
<ChartSeries Type="ChartSeriesType.Line" Name="Line 1" Data="@firstLineTypeData"> | ||
</ChartSeries> | ||
<ChartSeries Type="ChartSeriesType.Line" Name="Line 2" Data="@secondLineTypeData"> | ||
</ChartSeries> | ||
</ChartSeriesItems> | ||
|
||
<ChartCategoryAxes> | ||
<ChartCategoryAxis Categories="@xColumnAxisItems"></ChartCategoryAxis> | ||
</ChartCategoryAxes> | ||
|
||
<ChartTitle Text="Draw Horizontal and Vertical Lines"></ChartTitle> | ||
|
||
<ChartLegend Position="ChartLegendPosition.Right"> | ||
</ChartLegend> | ||
</TelerikChart> | ||
|
||
@code { | ||
#region LinesData | ||
private List<object> firstColumnTypeData = new List<object>() { 10, 2, 5, 6 }; | ||
private List<object> secondColumnTypeData = new List<object>() { 5, 8, 2, 7 }; | ||
|
||
private List<object> firstLineTypeData = new List<object>() { 8, 8, 8, 6 }; | ||
private List<object> secondLineTypeData = new List<object>() { 5, 8, 2, 7 }; | ||
|
||
private string[] xColumnAxisItems = new string[] { "Q1", "Q2", "Q3", "Q4" }; | ||
#endregion | ||
} | ||
```` | ||
|
||
## See Also | ||
|
||
* [Charts Plot Bands]({%slug chart-plot-bands%}) | ||
* [Lines Chart](https://demos.telerik.com/blazor-ui/chart/line-chart) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.