Render a bar chart by setting Type="bar" on the FluentUIChart component. Pass a list of category labels and one or more ChartDataset objects to define the bars. FluentUIChart is a theme-aware wrapper around the underlying Chart component, which is built on top of Chart.js.
A bar chart with three uncolored datasets — colors are filled in from the active Fluent palette. Click any bar to see the click event payload, and toggle the site theme between Light and Dark to see the chart re-theme in place.
import { ChartType, type ChartDataset } from '@powerportalspro/react-charts';
import { FluentUIChart } from '@powerportalspro/react-fluent';
const LABELS = ['Jan', 'Feb', 'Mar'];
const DATASETS: ChartDataset[] = [
{
label: 'Sales',
data: [{ value: 65 }, { value: 59 }, { value: 80 }],
},
{
label: 'Returns',
data: [{ value: 12 }, { value: 19 }, { value: 8 }],
},
];
export function MyChart() {
return <FluentUIChart type={ChartType.Bar} labels={LABELS} datasets={DATASETS} />;
}<FluentUIChart Type="ChartType.Bar"
Labels="_labels"
Datasets="_datasets" />
@code {
private List<string> _labels = new() { "Jan", "Feb", "Mar" };
private List<ChartDataset> _datasets = new()
{
new ChartDataset
{
Label = "Sales",
Data = new List<DataPoint>
{
new DataPoint(65), new DataPoint(59), new DataPoint(80),
},
},
new ChartDataset
{
Label = "Returns",
Data = new List<DataPoint>
{
new DataPoint(12), new DataPoint(19), new DataPoint(8),
},
},
};
}Chart.js renders to an HTML <canvas>, so CSS cannot reach into bars, axis labels, or gridlines — they are rasterized pixels. FluentUIChart works around this by reading the resolved CSS custom properties at render time and pushing the values into the Chart.js options as color, scale.ticks.color, and scale.grid.color. It subscribes to ThemeService.ThemeChanged and reapplies the palette whenever the theme changes.
Datasets that leave BackgroundColor or BorderColor null are auto-filled from a Fluent-derived series palette starting with the current accent color. Datasets that supply explicit colors are passed through unchanged.
Subscribe to OnElementClick to be notified when the user clicks on a bar (or any rendered element). The callback receives a ChartClickEventArgs with the dataset index, data index, label, value, dataset label, and the original IDataPoint instance. Subclass DataPoint to attach caller-defined context (record id, region, category, etc.) and pattern-match against your subclass in the click handler to recover it. Clicks on the chart background are ignored.
import {
ChartType,
type BaseDataPoint,
type ChartClickEventArgs,
type ChartDataset,
} from '@powerportalspro/react-charts';
import { FluentUIChart } from '@powerportalspro/react-fluent';
// Extend BaseDataPoint to attach caller-defined context (region, record id,
// category, etc.). Parameterizing <FluentUIChart> with this type below
// flows it through to args.dataPoint — no casts required.
interface SalesDataPoint extends BaseDataPoint {
region: string;
}
const DATASETS: ChartDataset<SalesDataPoint>[] = [/* ... */];
function onBarClicked(args: ChartClickEventArgs<SalesDataPoint>) {
const region = args.dataPoint?.region ?? '';
console.log(`${args.label}: ${args.value} (${region})`);
}
export function MyChart() {
return (
<FluentUIChart<SalesDataPoint>
type={ChartType.Bar}
labels={LABELS}
datasets={DATASETS}
onElementClick={onBarClicked}
/>
);
}<FluentUIChart Type="ChartType.Bar"
Labels="_labels"
Datasets="_datasets"
OnElementClick="OnBarClicked" />
@code {
private class SalesDataPoint : DataPoint
{
public SalesDataPoint(double value) : base(value) { }
public string Region { get; set; } = string.Empty;
}
private void OnBarClicked(ChartClickEventArgs args)
{
// Pattern-match args.DataPoint to recover any caller-defined context.
if (args.DataPoint is SalesDataPoint sdp)
{
Console.WriteLine($"{args.Label}: {sdp.Value} ({sdp.Region})");
}
}
}Set Title to display a heading above the chart. The title is rendered by Chart.js inside the canvas and uses the current theme's text color.
<DataverseChart dataSource={source}
type={ChartType.Bar}
title="Revenue by Year" /><DataverseChart Source="_source"
Type="ChartType.Bar"
Title="Revenue by Year" />Set Stacked="true" to stack datasets on top of each other rather than side-by-side. This is useful for bar and line charts with multiple series where the total across all series is meaningful (e.g. total revenue = won + lost).
<DataverseChart dataSource={source}
type={ChartType.Bar}
stacked /><DataverseChart Source="_source"
Type="ChartType.Bar"
Stacked="true" />Set LegendPosition to control where the legend appears: "top" (default), "bottom", "left", "right", or "hidden" to hide it entirely.
// Position: Top (default), Bottom, Left, Right
<DataverseChart dataSource={source}
legendPosition={ChartLegendPosition.Bottom} />
// Hide the legend entirely
<DataverseChart dataSource={source}
legendPosition={ChartLegendPosition.Hidden} /><!-- Position: Top (default), Bottom, Left, Right -->
<DataverseChart Source="_source"
LegendPosition="ChartLegendPosition.Bottom" />
<!-- Hide the legend entirely -->
<DataverseChart Source="_source"
LegendPosition="ChartLegendPosition.Hidden" />With no format, a chart shows its values and labels its own way. Give it one where you know better how they should read: each is a .NET format string, applied in the user's language.
ValueFormat (valueFormat in React) shapes the axis of values and the tooltips: a standard numeric format such as N0, C0, P1 or F2, or a custom one such as #,##0.0 or 0.0%. A C format shows the organization's base currency when the chart totals, averages or finds the least or most of a money column; set ValueCurrency (valueCurrency) to name another. The axis prefix and suffix still apply around it.GroupByFormat and SeriesFormat (groupByFormat, seriesFormat) shape the bars' labels and the datasets' names: a numeric format for a number column or the ends of a range, a date format such as MMMM yyyy for a date or a span of days, months or years, and for weeks or quarters a pattern with the week or quarter as {0} and the year as {1}, such as Q{0} {1}. A choice, lookup or text column keeps its names.const source = useMemo(
() =>
new AggregateDataverseChartDataSource({
tableName: 'opportunity',
groupByColumn: 'actualclosedate',
groupByDateGrouping: DateGrouping.Quarter,
groupByFormat: '{1} Q{0}', // 2024 Q1, 2024 Q2 …
aggregateColumn: 'estimatedvalue',
aggregate: QueryAggregate.Sum,
}),
[],
);
return <DataverseChart dataSource={source} type={ChartType.Bar} valueFormat="C0" />;<DataverseChart Source="_source"
Type="ChartType.Bar"
ValueFormat="C0" />
@code {
private readonly AggregateDataverseChartDataSource _source = new()
{
TableName = "opportunity",
GroupByColumn = "actualclosedate",
GroupByDateGrouping = DateGrouping.Quarter,
GroupByFormat = "{1} Q{0}", // 2024 Q1, 2024 Q2 …
AggregateColumn = "estimatedvalue",
Aggregate = QueryAggregate.Sum,
};
}Use AggregateDataverseChartDataSource to feed a chart from Dataverse without writing raw FetchXML. Set TableName, GroupByColumn, AggregateColumn, and Aggregate. Optionally add a SeriesColumn for multi-series, a GroupByDateGrouping for date bucketing, a ViewId to merge a saved view's filter conditions, or a FilterXml fragment for inline conditions.
import {
AggregateDataverseChartDataSource,
QueryAggregate,
DateGrouping,
ChartType,
type ChartClickEventArgs,
} from '@powerportalspro/react-charts';
import { DataverseChart } from '@powerportalspro/react-fluent';
import { useMemo } from 'react';
export function MyChart() {
// useMemo keeps the source's identity stable so the chart doesn't
// re-fetch on every render — changes to the config are applied at mount.
const source = useMemo(
() =>
new AggregateDataverseChartDataSource({
tableName: 'opportunity',
groupByColumn: 'actualclosedate',
groupByDateGrouping: DateGrouping.Year,
aggregateColumn: 'estimatedvalue',
aggregate: QueryAggregate.Sum,
seriesColumn: 'statecode',
filterXml:
"<filter><condition attribute='statecode' operator='ne' value='0' /></filter>",
}),
[],
);
const onBarClicked = (args: ChartClickEventArgs) => {
// args.datasetLabel, args.label, args.value, args.dataPoint
};
return (
<DataverseChart
dataSource={source}
type={ChartType.Bar}
title="Estimated Revenue by Year (Stacked)"
stacked
yAxisPrefix="$"
onElementClick={onBarClicked}
/>
);
}<DataverseChart Source="_source"
Type="ChartType.Bar"
Title="Estimated Revenue by Year (Stacked)"
Stacked="true"
YAxisPrefix="$"
OnElementClick="OnBarClicked" />
@code {
private readonly AggregateDataverseChartDataSource _source = new()
{
TableName = "opportunity",
GroupByColumn = "actualclosedate",
GroupByDateGrouping = DateGrouping.Year,
AggregateColumn = "estimatedvalue",
Aggregate = QueryAggregate.Sum,
SeriesColumn = "statecode",
FilterXml = "<filter><condition attribute='statecode' operator='ne' value='0' /></filter>",
};
private void OnBarClicked(ChartClickEventArgs args)
{
// args.DatasetLabel, args.Label, args.Value, args.DataPoint
}
}Estimated opportunity revenue by year, split by status (Won vs Lost) and stacked — loaded from Dataverse via AggregateDataverseChartDataSource. Click a bar to see the year, status, and revenue.
A date column groups by the span of time each bar covers, set with GroupByDateGrouping. Dataverse groups dates by the day at its finest, so for minutes and hours the chart reads each record's time, in the user's time zone, and adds the records up itself — as many as it reads for a grouping in ranges.
Minute, Hour, Day, Week, Month, Quarter and Year — puts the bars along a timeline: January 2024, February 2024, and so on. Weeks are ISO weeks, Monday to Sunday.MinuteOfHour, HourOfDay, DayOfWeek, DayOfMonth, WeekOfYear, MonthOfYear and QuarterOfYear — folds every repeat onto the same bar: every January together whatever its year, or every day's nine o'clock hour. Minutes, hours and the days of the week get a bar each, one with no records a bar of zero.GroupByRangeSize, which sets how much of a number each bar covers, sets how many minutes or hours each bar covers: 15 for every quarter of an hour, 1.5 for every hour and a half. It must divide an hour or a day evenly into whole minutes.FiscalPeriod and FiscalYear follow the organization's fiscal settings and are named as it names them, such as Quarter 3 FY2026.The opportunities by the hour of the day they were created, two hours to a bar, every day's folded together: GroupByDateGrouping = DateGrouping.HourOfDay with GroupByRangeSize = 2.
Pass ViewIds and DefaultViewId on DataverseChart to display a view selector dropdown above the chart. When the user switches views, the selected view's filter conditions are merged into the aggregate query and the chart reloads. The ViewId on the source is not set directly — DataverseChart manages it. The view determines which records are included; the aggregate config determines how they're grouped and summarized.
import {
AggregateDataverseChartDataSource,
QueryAggregate,
DateGrouping,
ChartType,
} from '@powerportalspro/react-charts';
import { DataverseChart } from '@powerportalspro/react-fluent';
import { useMemo } from 'react';
const VIEW_IDS = [
'...', // Won Opportunities
'...', // All Opportunities
];
const DEFAULT_VIEW_ID = VIEW_IDS[0];
export function MyChart() {
const source = useMemo(
() =>
new AggregateDataverseChartDataSource({
tableName: 'opportunity',
groupByColumn: 'actualclosedate',
groupByDateGrouping: DateGrouping.Month,
aggregateColumn: 'estimatedvalue',
aggregate: QueryAggregate.Sum,
}),
[],
);
return (
<DataverseChart
dataSource={source}
type={ChartType.Bar}
viewIds={VIEW_IDS}
defaultViewId={DEFAULT_VIEW_ID}
yAxisPrefix="$"
/>
);
}<DataverseChart Source="_source"
Type="ChartType.Bar"
ViewIds="_viewIds"
DefaultViewId="@_defaultViewId"
YAxisPrefix="$" />
@code {
private static readonly List<Guid> _viewIds = new()
{
new Guid("..."), // Won Opportunities
new Guid("..."), // All Opportunities
};
private static readonly Guid _defaultViewId = _viewIds[0];
private readonly AggregateDataverseChartDataSource _source = new()
{
TableName = "opportunity",
GroupByColumn = "actualclosedate",
GroupByDateGrouping = DateGrouping.Month,
AggregateColumn = "estimatedvalue",
Aggregate = QueryAggregate.Sum,
};
}Estimated revenue by month with a view selector dropdown. Switch between views to see the chart reload with different filter criteria.
Set GroupByLinkedEntity (or SeriesLinkedEntity) to group or split by a column on a related table. The builder creates a <link-entity> join and places the groupby attribute inside it. Supports unlimited nesting via ChartLinkedEntity.LinkedEntity for multi-hop joins.
import {
AggregateDataverseChartDataSource,
QueryAggregate,
ChartType,
} from '@powerportalspro/react-charts';
import { DataverseChart } from '@powerportalspro/react-fluent';
import { useMemo } from 'react';
export function MyChart() {
const source = useMemo(
() =>
new AggregateDataverseChartDataSource({
tableName: 'opportunity',
groupByColumn: 'industrycode',
groupByLinkedEntity: {
tableName: 'account',
from: 'accountid',
to: 'customerid',
},
aggregateColumn: 'estimatedvalue',
aggregate: QueryAggregate.Sum,
}),
[],
);
return (
<DataverseChart
dataSource={source}
type={ChartType.Bar}
title="Revenue by Industry"
yAxisPrefix="$"
/>
);
}<DataverseChart Source="_source"
Type="ChartType.Bar"
Title="Revenue by Industry"
YAxisPrefix="$" />
@code {
private readonly AggregateDataverseChartDataSource _source = new()
{
TableName = "opportunity",
GroupByColumn = "industrycode",
GroupByLinkedEntity = new ChartLinkedEntity
{
TableName = "account",
From = "accountid",
To = "customerid",
},
AggregateColumn = "estimatedvalue",
Aggregate = QueryAggregate.Sum,
};
}The above configuration generates the following FetchXML:
<fetch aggregate="true">
<entity name="opportunity">
<attribute name="estimatedvalue" alias="estimatedvalue" aggregate="sum" />
<link-entity name="account" from="accountid" to="customerid" link-type="inner">
<attribute name="industrycode" alias="industrycode" groupby="true" />
<order alias="industrycode" />
</link-entity>
</entity>
</fetch>
Total estimated opportunity revenue grouped by the parent account's industry — the industrycode column lives on the account table, joined via customerid.
See Also
Chart API Reference — complete documentation for all chart classes, enums, and data sources.