1+ @page " /stackedbar"
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 = Align .Center ,
40+ Display = true ,
41+ Position = LegendPosition .Right
42+ }
43+ },
44+ Scales = new Dictionary & lt ;string , Axis > ()
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+ IndexAxis = Axes .Y
65+ }
66+ };
67+
68+ _config1 .Data .Labels = BarDataExamples .GroupedLabels ;
69+ _config1 .Data .Datasets .Add (new BarDataset ()
70+ {
71+ Label = " Value" ,
72+ Data = BarDataExamples .Grouped1 ,
73+ BackgroundColor = new List & lt ;string > () { Colors .Palette1 .First () },
74+ BorderColor = new List & lt ;string > () { Colors .Palette1 .First () },
75+ BorderWidth = 1
76+ });
77+ _config1 .Data .Datasets .Add (new BarDataset ()
78+ {
79+ Label = " Value2" ,
80+ Data = BarDataExamples .Grouped2 ,
81+ BackgroundColor = new List & lt ;string > () { Colors .PaletteBorder1 .First () },
82+ BorderColor = new List & lt ;string > () { Colors .PaletteBorder1 .First () },
83+ BorderWidth = 1
84+ });
85+ }
86+ </CodeSnippet >
87+
88+ @code {
89+ private BarChartConfig ? _config1 ;
90+ private Chart ? _chart1 ;
91+
92+ protected override async Task OnInitializedAsync ()
93+ {
94+ _config1 = new BarChartConfig ()
95+ {
96+ Options = new Options ()
97+ {
98+ Responsive = true ,
99+ MaintainAspectRatio = false ,
100+ Plugins = new Plugins ()
101+ {
102+ Legend = new Legend ()
103+ {
104+ Align = Align .Center ,
105+ Display = true ,
106+ Position = LegendPosition .Right
107+ }
108+ },
109+ Scales = new Dictionary <string , Axis >()
110+ {
111+ {
112+ Scales .XAxisId , new Axis ()
113+ {
114+ Stacked = true ,
115+ Ticks = new Ticks ()
116+ {
117+ MaxRotation = 0 ,
118+ MinRotation = 0
119+ }
120+ }
121+ },
122+ {
123+ Scales .YAxisId , new Axis ()
124+ {
125+ Stacked = true
126+ }
127+ }
128+ },
129+ IndexAxis = Axes .Y
130+ }
131+ };
132+
133+ _config1 .Data .Labels = BarDataExamples .GroupedLabels ;
134+ _config1 .Data .Datasets .Add (new BarDataset ()
135+ {
136+ Label = " Value" ,
137+ Data = BarDataExamples .Grouped1 ,
138+ BackgroundColor = new List <string >() { Colors .Palette1 .First () },
139+ BorderColor = new List <string >() { Colors .Palette1 .First () },
140+ BorderWidth = 1
141+ });
142+ _config1 .Data .Datasets .Add (new BarDataset ()
143+ {
144+ Label = " Value2" ,
145+ Data = BarDataExamples .Grouped2 ,
146+ BackgroundColor = new List <string >() { Colors .PaletteBorder1 .First () },
147+ BorderColor = new List <string >() { Colors .PaletteBorder1 .First () },
148+ BorderWidth = 1
149+ });
150+ }
151+ }
0 commit comments