1+ @page " /barSimple"
2+
3+ <h3 >Bar Simple</h3 >
4+
5+ <Chart Config =" _config1" @ref =" _chart1" Height =" 400px" ></Chart >
6+
7+ <hr />
8+
9+ <h3 >Code</h3 >
10+
11+ <p >
12+ This is the component to add in your page.
13+ </p >
14+
15+ <CodeSnippet Language =" Language.xml" Style =" Style.VisualStudio" >
16+ <Chart Config="_config1" @ ; ref="_chart1">< ; Chart>
17+ </CodeSnippet >
18+
19+ <p >
20+ Then, in the code section, add the following code:
21+ </p >
22+
23+ <CodeSnippet Language =" Language.csharp" Style =" Style.VisualStudio" LoadMainScript =" false" >
24+ private BarChartConfig? _config1;
25+ private Chart? _chart1;
26+
27+ protected override async Task OnInitializedAsync()
28+ {
29+ _config1 = new BarChartConfig ()
30+ {
31+ Options = new Options ()
32+ {
33+ Responsive = true ,
34+ MaintainAspectRatio = false ,
35+ Plugins = new Plugins ()
36+ {
37+ Legend = new Legend ()
38+ {
39+ Align = LegendAlign .Center ,
40+ Display = false ,
41+ Position = LegendPosition .Right
42+ }
43+ },
44+ Scales = new Dictionary & lt ;string , Axis & gt ;()
45+ {
46+ {
47+ Scales .XAxisId , new Axis ()
48+ {
49+ Stacked = true ,
50+ Ticks = new Ticks ()
51+ {
52+ MaxRotation = 0 ,
53+ MinRotation = 0
54+ }
55+ }
56+ },
57+ {
58+ Scales .YAxisId , new Axis ()
59+ {
60+ Stacked = true
61+ }
62+ }
63+ }
64+ }
65+ };
66+
67+ _config1 .Data .Labels = BarDataExamples .SimpleBarText ;
68+ _config1 .Data .Datasets .Add (new BarDataset ()
69+ {
70+ Label = " Value" ,
71+ Data = BarDataExamples .SimpleBar .Select (l => l .Value ).ToList (),
72+ BackgroundColor = Colors .Palette1 ,
73+ BorderColor = Colors .PaletteBorder1 ,
74+ BorderWidth = 1
75+ });
76+ }
77+ </CodeSnippet >
78+
79+ @code {
80+ private BarChartConfig ? _config1 ;
81+ private Chart ? _chart1 ;
82+
83+ protected override async Task OnInitializedAsync ()
84+ {
85+ _config1 = new BarChartConfig ()
86+ {
87+ Options = new Options ()
88+ {
89+ Responsive = true ,
90+ MaintainAspectRatio = false ,
91+ Plugins = new Plugins ()
92+ {
93+ Legend = new Legend ()
94+ {
95+ Align = Align .Center ,
96+ Display = false ,
97+ Position = LegendPosition .Right
98+ }
99+ },
100+ Scales = new Dictionary <string , Axis >()
101+ {
102+ {
103+ Scales .XAxisId , new Axis ()
104+ {
105+ Stacked = true ,
106+ Ticks = new Ticks ()
107+ {
108+ MaxRotation = 0 ,
109+ MinRotation = 0
110+ }
111+ }
112+ },
113+ {
114+ Scales .YAxisId , new Axis ()
115+ {
116+ Stacked = true
117+ }
118+ }
119+ }
120+ }
121+ };
122+
123+ _config1 .Data .Labels = BarDataExamples .SimpleBarText ;
124+ _config1 .Data .Datasets .Add (new BarDataset ()
125+ {
126+ Label = " Value" ,
127+ Data = BarDataExamples .SimpleBar .Select (l => l .Value ).ToList (),
128+ BackgroundColor = Colors .Palette1 ,
129+ BorderColor = Colors .PaletteBorder1 ,
130+ BorderWidth = 1
131+ });
132+ }
133+ }
0 commit comments