Bar Chart
Bars for each category, side by side, stacked or lying down.
A bar per series for each category, drawn by the component in the theme's chart colours, with a legend, a tooltip and a grow-in animation. See Charts for how data, colours and updates work in every chart.
Installation
shellui-native add bar-chart
Platforms: MAUI · Avalonia. Also installs chart, the core every chart shares. The chart colours are theme tokens added with the charts, so in a project whose shell came from an older CLI, run shellui-native update shell first.
Usage
Basic
Each ChartSeries is a set of bars; Labels names the categories along the axis.
<ui:BarChart Labels="Jan, Feb, Mar, Apr, May, Jun" Description="Downloads by month" HeightRequest="260">
<ui:ChartSeries Name="ShellUI" Values="186, 305, 237, 273, 309, 344" />
<ui:ChartSeries Name="ShellUI Native" Values="80, 120, 160, 190, 230, 270" />
</ui:BarChart><ui:BarChart Labels="Jan, Feb, Mar, Apr, May, Jun" Description="Downloads by month" Height="260">
<ui:ChartSeries Name="ShellUI" Values="186, 305, 237, 273, 309, 344" />
<ui:ChartSeries Name="ShellUI Native" Values="80, 120, 160, 190, 230, 270" />
</ui:BarChart>Stacked
IsStacked puts each series on top of the one before it. Only the top of a stack is rounded.
<ui:BarChart Labels="Jan, Feb, Mar, Apr, May, Jun" IsStacked="True" HeightRequest="260">
<ui:ChartSeries Name="ShellUI" Values="186, 305, 237, 273, 309, 344" />
<ui:ChartSeries Name="ShellUI Native" Values="80, 120, 160, 190, 230, 270" />
</ui:BarChart><ui:BarChart Labels="Jan, Feb, Mar, Apr, May, Jun" IsStacked="True" Height="260">
<ui:ChartSeries Name="ShellUI" Values="186, 305, 237, 273, 309, 344" />
<ui:ChartSeries Name="ShellUI Native" Values="80, 120, 160, 190, 230, 270" />
</ui:BarChart>Horizontal
IsHorizontal lays the bars down: categories run down the side and values along the bottom. Negative values go the other way.
<ui:BarChart Labels="button, input, card, dialog, select" IsHorizontal="True" ShowLegend="False" HeightRequest="260">
<ui:ChartSeries Name="Installs" Values="420, 360, 310, 240, 190" />
</ui:BarChart><ui:BarChart Labels="button, input, card, dialog, select" IsHorizontal="True" ShowLegend="False" Height="260">
<ui:ChartSeries Name="Installs" Values="420, 360, 310, 240, 190" />
</ui:BarChart>MAUI and Avalonia
- MAUI draws the chart in a
GraphicsView; give it aHeightRequest. On touch screens a tap or a drag shows the tooltip. - Avalonia draws it in
Render, in the control's own font; give it aHeight.ChartSeries.Coloris an AvaloniaColor(Color.Parse("#E76E50")).
API
BarChart
XAML children go to Series.
| Property | Type | Default | Description |
|---|---|---|---|
IsStacked |
bool |
false |
Stacks the series on top of each other instead of side by side. |
IsHorizontal |
bool |
false |
Lays the bars down: categories run down the side, values along the bottom. |
CornerRadius |
double |
4 |
Rounds the end of each bar (the end of each stack when stacked). |
MaxBarSize |
double |
56 |
The thickest a bar gets, however much room there is. |
ShowGrid |
bool |
true |
Grid lines behind the plot, at each value axis step. |
ShowXAxis |
bool |
true |
The labels under the plot. |
ShowYAxis |
bool |
true |
The labels beside the plot. |
Minimum |
double |
Fits the data | The ends of the value axis; by default they fit the data and include zero. |
Maximum |
double |
Fits the data | The other end of the value axis; see Minimum. |
Labels |
ChartLabels (MAUI) · ChartLabels? (Avalonia) |
null |
The category names along the axis, or the slice names of a pie. |
ShowLegend |
bool |
true |
Shows the series (or slice) names with their colours under the chart. |
ShowTooltip |
bool |
true |
Shows the values under the pointer (or the finger). |
IsAnimated |
bool |
true |
Grows the chart in when it first appears. |
ValueFormat |
string |
"#,0.##" |
A .NET number format for axis and tooltip values. |
EmptyText |
string |
"No data" |
Shown when there are no values. |
Description |
string |
— | What the chart shows, for screen readers. |
| Method | Description |
|---|---|
Refresh() |
Redraws the chart. Call it after changing the numbers inside a series' Values. |
PlayAnimation() |
Grows the chart in again. |
ChartSeries
| Property | Type | Default | Description |
|---|---|---|---|
Name |
string |
— | Shown in the legend and the tooltip. |
Values |
ChartValues |
Empty | The numbers, one per category. In XAML, a comma-separated list. |
Color |
Color? |
null |
Replaces the theme's chart color for this series. |