|
| 1 | +--- |
| 2 | +title: Overview |
| 3 | +page_title: Arc Gauge Overview |
| 4 | +description: Overview of the Arc Gauge for Blazor. |
| 5 | +slug: arc-gauge-overview |
| 6 | +tags: telerik,blazor,chart,overview |
| 7 | +published: True |
| 8 | +position: 0 |
| 9 | +--- |
| 10 | + |
| 11 | +# Chart Overview |
| 12 | + |
| 13 | +The <a href="https://www.telerik.com/blazor-ui/chart" target="_blank">Blazor Chart component</a> allows you to visualize data to your users in a meaningful way so they can draw conclusions. You can use a variety of chart types and control all aspects of the chart's appearance - from colors and fonts, to paddings, margins and templates. |
| 14 | + |
| 15 | +#### To use a Telerik chart for Blazor, add the `TelerikChart` tag. |
| 16 | + |
| 17 | +>caption Basic chart with series and category axis [data binding](data-bind), and a few commonly used appearance settings |
| 18 | +
|
| 19 | +````CSHTML |
| 20 | +Basic chart and common settings/elements |
| 21 | +
|
| 22 | +<TelerikChart> |
| 23 | + <ChartSeriesItems> |
| 24 | + <ChartSeries Type="ChartSeriesType.Line" Name="Product 1 (bound to simple data)" Data="@simpleData"> |
| 25 | + </ChartSeries> |
| 26 | + <ChartSeries Type="ChartSeriesType.Line" Name="Product 2 (bound to model)" Data="@modelData" Field="@nameof(MyDataModel.SecondSeriesValue)"> |
| 27 | + <ChartSeriesLabels Template="#=value# in #=dataItem.ExtraData# quarter" Visible="true"></ChartSeriesLabels> |
| 28 | + </ChartSeries> |
| 29 | + </ChartSeriesItems> |
| 30 | +
|
| 31 | + <ChartValueAxes> |
| 32 | + <ChartValueAxis Color="red"></ChartValueAxis> |
| 33 | + </ChartValueAxes> |
| 34 | +
|
| 35 | + <ChartCategoryAxes> |
| 36 | + <ChartCategoryAxis Categories="@xAxisItems"></ChartCategoryAxis> |
| 37 | + </ChartCategoryAxes> |
| 38 | +
|
| 39 | + <ChartTitle Text="Quarterly sales trend"></ChartTitle> |
| 40 | +
|
| 41 | + <ChartLegend Position="Telerik.Blazor.ChartLegendPosition.Bottom"> |
| 42 | + </ChartLegend> |
| 43 | +</TelerikChart> |
| 44 | +
|
| 45 | +@code { |
| 46 | + public class MyDataModel |
| 47 | + { |
| 48 | + public int SecondSeriesValue { get; set; } |
| 49 | + public string ExtraData { get; set; } |
| 50 | +
|
| 51 | + } |
| 52 | +
|
| 53 | + public List<MyDataModel> modelData = new List<MyDataModel>() |
| 54 | + { |
| 55 | + new MyDataModel() { SecondSeriesValue = 1, ExtraData = "first" }, |
| 56 | + new MyDataModel() { SecondSeriesValue = 5, ExtraData = "second" }, |
| 57 | + new MyDataModel() { SecondSeriesValue = 3, ExtraData = "third" }, |
| 58 | + new MyDataModel() { SecondSeriesValue = 2, ExtraData = "fourth" }, |
| 59 | + }; |
| 60 | +
|
| 61 | + public List<object> simpleData = new List<object>() { 10, 2, 7, 5 }; |
| 62 | +
|
| 63 | + public string[] xAxisItems = new string[] { "Q1", "Q2", "Q3", "Q4" }; |
| 64 | +} |
| 65 | +```` |
| 66 | + |
| 67 | +>caption The result from the code snippet above |
| 68 | +
|
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +@[template](/_contentTemplates/chart/link-to-basics.md#configurable-nested-chart-settings) |
| 74 | + |
| 75 | +>caption Component namespace and reference |
| 76 | +
|
| 77 | +````CSHTML |
| 78 | +@using Telerik.Blazor.Components |
| 79 | +
|
| 80 | +<TelerikChart @ref="myChartRef"> |
| 81 | +</TelerikChart> |
| 82 | +
|
| 83 | +@code { |
| 84 | + Telerik.Blazor.Components.TelerikChart myChartRef; |
| 85 | +} |
| 86 | +```` |
| 87 | + |
| 88 | +## Chart Size |
| 89 | + |
| 90 | +To control the chart size, use its `Width` and `Height` properties. You can read more on how they work in the [Dimensions]({%slug common-features/dimensions%}) article. |
| 91 | + |
| 92 | +You can also set the chart size in percentage values so it occupies its container when it renderes. If the parent container size changes, you must call the chart's `Refresh()` C# method after the DOM has been redrawn and the new container dimensions are rendered. You can do this when you explicitly change container sizes (like in the example below), or from code that gets called by events like `window.resize`. You can find an example of making charts redraw on `window.resize` in the [Responsive Chart](https://github.com/telerik/blazor-ui/tree/master/chart/responsive-chart) sample. |
| 93 | + |
| 94 | + |
| 95 | +>caption Change the 100% chart size dynamically to have a responsive chart |
| 96 | +
|
| 97 | +````CSHTML |
| 98 | +You can make a responsive chart |
| 99 | +
|
| 100 | +<TelerikButton OnClick="@ResizeChart">Resize the container and redraw the chart</TelerikButton> |
| 101 | +
|
| 102 | +<div style="border: 1px solid red;width:@ContainerWidth; height: @ContainerHeight"> |
| 103 | +
|
| 104 | + <TelerikChart Width ="100%" Height="100%" @ref="theChart"> |
| 105 | +
|
| 106 | + <ChartSeriesItems> |
| 107 | + <ChartSeries Type="ChartSeriesType.Column" Name="Product 1" Data="@someData"> |
| 108 | + </ChartSeries> |
| 109 | + </ChartSeriesItems> |
| 110 | + <ChartCategoryAxes> |
| 111 | + <ChartCategoryAxis Categories="@xAxisItems"></ChartCategoryAxis> |
| 112 | + </ChartCategoryAxes> |
| 113 | + <ChartTitle Text="Quarterly sales trend"></ChartTitle> |
| 114 | +
|
| 115 | + </TelerikChart> |
| 116 | +
|
| 117 | +</div> |
| 118 | +
|
| 119 | +@code { |
| 120 | + string ContainerWidth { get; set; } = "400px"; |
| 121 | + string ContainerHeight { get; set; } = "300px"; |
| 122 | + Telerik.Blazor.Components.TelerikChart theChart { get; set; } |
| 123 | +
|
| 124 | + async Task ResizeChart() |
| 125 | + { |
| 126 | + //resize the container |
| 127 | + ContainerHeight = "500px"; |
| 128 | + ContainerWidth = "800px"; |
| 129 | +
|
| 130 | + //give time to the framework and browser to resize the actual DOM so the chart can use the expected size |
| 131 | + await Task.Delay(20); |
| 132 | +
|
| 133 | + //redraw the chart |
| 134 | + theChart.Refresh(); |
| 135 | + } |
| 136 | +
|
| 137 | + public List<object> someData = new List<object>() { 10, 2, 7, 5 }; |
| 138 | +
|
| 139 | + public string[] xAxisItems = new string[] { "Q1", "Q2", "Q3", "Q4" }; |
| 140 | +} |
| 141 | +```` |
| 142 | + |
| 143 | +## See Also |
| 144 | + |
| 145 | + * [Data Binding]({%slug components/chart/databind%}) |
| 146 | + * [Live Demos: Chart](https://demos.telerik.com/blazor-ui/chart/index) |
| 147 | + * [API Reference](https://docs.telerik.com/blazor-ui/api/Telerik.Blazor.Components.TelerikChart) |
0 commit comments