|
| 1 | +@page "/crosshair" |
| 2 | + |
| 3 | +<h3>Line with crosshair</h3> |
| 4 | + |
| 5 | +<p> |
| 6 | + In every graph, you can add options. In the component, we added the <code>crossair</code>: this shows horizontal and vertical lines |
| 7 | + on the graph to identify better where a point is. See the example below. |
| 8 | +</p> |
| 9 | + |
| 10 | +<h4>Horizontal crosshair</h4> |
| 11 | + |
| 12 | +<Chart Config="_config1" @ref="_chart1" Height="400px"></Chart> |
| 13 | + |
| 14 | +<CodeSnippet Language="Language.xml" Style="Style.VisualStudio"> |
| 15 | +<Chart Config="_config1" @ref="_chart1"><Chart> |
| 16 | +</CodeSnippet> |
| 17 | + |
| 18 | +<CodeSnippet Language="Language.csharp" Style="Style.VisualStudio" LoadMainScript="false"> |
| 19 | +private LineChartConfig? _config1; |
| 20 | +private Chart? _chart1; |
| 21 | + |
| 22 | +protected override async Task OnInitializedAsync() |
| 23 | + _config1 = new LineChartConfig() |
| 24 | + { |
| 25 | + Options = new Options() |
| 26 | + { |
| 27 | + Plugins = new Plugins() |
| 28 | + { |
| 29 | + Crosshair = new Crosshair() |
| 30 | + { |
| 31 | + Vertical = new CrosshairLine() |
| 32 | + { |
| 33 | + Color = Colors.PaletteBorder1[0] |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + _config1.Data.Labels = LineDataExamples.SimpleLineText; |
| 41 | + _config1.Data.Datasets.Add(new LineDataset() |
| 42 | + { |
| 43 | + Label = "My First Dataset", |
| 44 | + Data = LineDataExamples.SimpleLine.ToList(), |
| 45 | + BorderColor = Colors.PaletteBorder1.FirstOrDefault(), |
| 46 | + Tension = 0.1M, |
| 47 | + Fill = false |
| 48 | + }); |
| 49 | +} |
| 50 | +</CodeSnippet> |
| 51 | + |
| 52 | +<hr/> |
| 53 | + |
| 54 | +<h4>Vertical crosshair</h4> |
| 55 | + |
| 56 | +<Chart Config="_config2" @ref="_chart1" Height="400px"></Chart> |
| 57 | + |
| 58 | +<CodeSnippet Language="Language.xml" Style="Style.VisualStudio"> |
| 59 | +<Chart Config="_config2" @ref="_chart1"><Chart> |
| 60 | +</CodeSnippet> |
| 61 | + |
| 62 | +<CodeSnippet Language="Language.csharp" Style="Style.VisualStudio" LoadMainScript="false"> |
| 63 | +private LineChartConfig? _config2; |
| 64 | +private Chart? _chart2; |
| 65 | + |
| 66 | +protected override async Task OnInitializedAsync() |
| 67 | + _config2 = new LineChartConfig() |
| 68 | + { |
| 69 | + Options = new Options() |
| 70 | + { |
| 71 | + Plugins = new Plugins() |
| 72 | + { |
| 73 | + Crosshair = new Crosshair() |
| 74 | + { |
| 75 | + Horizontal = new CrosshairLine() |
| 76 | + { |
| 77 | + Color = Colors.PaletteBorder1[0] |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + }; |
| 83 | + |
| 84 | + _config2.Data.Labels = LineDataExamples.SimpleLineText; |
| 85 | + _config2.Data.Datasets.Add(new LineDataset() |
| 86 | + { |
| 87 | + Label = "My First Dataset", |
| 88 | + Data = LineDataExamples.SimpleLine.ToList(), |
| 89 | + BorderColor = Colors.PaletteBorder1.FirstOrDefault(), |
| 90 | + Tension = 0.1M, |
| 91 | + Fill = false |
| 92 | + }); |
| 93 | +} |
| 94 | +</CodeSnippet> |
| 95 | + |
| 96 | +<hr /> |
| 97 | + |
| 98 | +<h4>Horizontal & Vertical crosshair</h4> |
| 99 | + |
| 100 | +<Chart Config="_config3" @ref="_chart1" Height="400px"></Chart> |
| 101 | + |
| 102 | +<CodeSnippet Language="Language.xml" Style="Style.VisualStudio"> |
| 103 | +<Chart Config="_config3" @ref="_chart1"><Chart> |
| 104 | +</CodeSnippet> |
| 105 | + |
| 106 | +<CodeSnippet Language="Language.csharp" Style="Style.VisualStudio" LoadMainScript="false"> |
| 107 | +private LineChartConfig? _config3; |
| 108 | +private Chart? _chart3; |
| 109 | + |
| 110 | +protected override async Task OnInitializedAsync() |
| 111 | +{ |
| 112 | + _config3 = new LineChartConfig() |
| 113 | + { |
| 114 | + Options = new Options() |
| 115 | + { |
| 116 | + Plugins = new Plugins() |
| 117 | + { |
| 118 | + Crosshair = new Crosshair() |
| 119 | + { |
| 120 | + Horizontal = new CrosshairLine() |
| 121 | + { |
| 122 | + Color = Colors.PaletteBorder1[0] |
| 123 | + }, |
| 124 | + Vertical = new CrosshairLine() |
| 125 | + { |
| 126 | + Color = Colors.PaletteBorder1[0] |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + }; |
| 132 | + |
| 133 | + _config3.Data.Labels = LineDataExamples.SimpleLineText; |
| 134 | + _config3.Data.Datasets.Add(new LineDataset() |
| 135 | + { |
| 136 | + Label = "My First Dataset", |
| 137 | + Data = LineDataExamples.SimpleLine.ToList(), |
| 138 | + BorderColor = Colors.PaletteBorder1.FirstOrDefault(), |
| 139 | + Tension = 0.1M, |
| 140 | + Fill = false |
| 141 | + }); |
| 142 | +} |
| 143 | +</CodeSnippet> |
| 144 | + |
| 145 | +@code { |
| 146 | + private LineChartConfig? _config1; |
| 147 | + private LineChartConfig? _config2; |
| 148 | + private LineChartConfig? _config3; |
| 149 | + |
| 150 | + private Chart? _chart1; |
| 151 | + private Chart? _chart2; |
| 152 | + private Chart? _chart3; |
| 153 | + |
| 154 | + protected override async Task OnInitializedAsync() |
| 155 | + { |
| 156 | + _config1 = new LineChartConfig() |
| 157 | + { |
| 158 | + Options = new Options() |
| 159 | + { |
| 160 | + Plugins = new Plugins() |
| 161 | + { |
| 162 | + Crosshair = new Crosshair() |
| 163 | + { |
| 164 | + Vertical = new CrosshairLine() |
| 165 | + { |
| 166 | + Color = Colors.PaletteBorder1[0] |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + }; |
| 172 | + |
| 173 | + _config1.Data.Labels = LineDataExamples.SimpleLineText; |
| 174 | + _config1.Data.Datasets.Add(new LineDataset() |
| 175 | + { |
| 176 | + Label = "My First Dataset", |
| 177 | + Data = LineDataExamples.SimpleLine.ToList(), |
| 178 | + BorderColor = Colors.PaletteBorder1.FirstOrDefault(), |
| 179 | + Tension = 0.1M, |
| 180 | + Fill = false |
| 181 | + }); |
| 182 | + |
| 183 | + _config2 = new LineChartConfig() |
| 184 | + { |
| 185 | + Options = new Options() |
| 186 | + { |
| 187 | + Plugins = new Plugins() |
| 188 | + { |
| 189 | + Crosshair = new Crosshair() |
| 190 | + { |
| 191 | + Horizontal = new CrosshairLine() |
| 192 | + { |
| 193 | + Color = Colors.PaletteBorder1[0] |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + }; |
| 199 | + |
| 200 | + _config2.Data.Labels = LineDataExamples.SimpleLineText; |
| 201 | + _config2.Data.Datasets.Add(new LineDataset() |
| 202 | + { |
| 203 | + Label = "My First Dataset", |
| 204 | + Data = LineDataExamples.SimpleLine.ToList(), |
| 205 | + BorderColor = Colors.PaletteBorder1.FirstOrDefault(), |
| 206 | + Tension = 0.1M, |
| 207 | + Fill = false |
| 208 | + }); |
| 209 | + |
| 210 | + _config3 = new LineChartConfig() |
| 211 | + { |
| 212 | + Options = new Options() |
| 213 | + { |
| 214 | + Plugins = new Plugins() |
| 215 | + { |
| 216 | + Crosshair = new Crosshair() |
| 217 | + { |
| 218 | + Horizontal = new CrosshairLine() |
| 219 | + { |
| 220 | + Color = Colors.PaletteBorder1[0] |
| 221 | + }, |
| 222 | + Vertical = new CrosshairLine() |
| 223 | + { |
| 224 | + Color = Colors.PaletteBorder1[0] |
| 225 | + } |
| 226 | + } |
| 227 | + } |
| 228 | + } |
| 229 | + }; |
| 230 | + |
| 231 | + _config3.Data.Labels = LineDataExamples.SimpleLineText; |
| 232 | + _config3.Data.Datasets.Add(new LineDataset() |
| 233 | + { |
| 234 | + Label = "My First Dataset", |
| 235 | + Data = LineDataExamples.SimpleLine.ToList(), |
| 236 | + BorderColor = Colors.PaletteBorder1.FirstOrDefault(), |
| 237 | + Tension = 0.1M, |
| 238 | + Fill = false |
| 239 | + }); |
| 240 | + } |
| 241 | +} |
0 commit comments