Repository navigation
Meet the WinUI Chart control: native charts for your WinUI 3 apps 📈 #12343
Pranav Gupta (pranav-gupta-msft)
announced in
Announcements
Replies: 5 comments 5 replies
I identified a few serious issues with this control:First, there is an actual bugPlease fix it before stable: #12350 Lacking animationsWe should have animations when the data is changing or the user is hovering over it. (this is nice to have) Lacking fluent design styleIt does look like the current control comes from another UI framework, which I'm 90% sure is true, and does not fit the fluent design language in any way. This is how a WinUI chart control should look like:
I don't think the control should leave experimental until it matches fluent design. Feels more like a workaround than a first-party control. |
0 replies
|
Could you add zoom and pan functionality, as well as a trackball feature, to the charts? |
0 replies
|
there is no pie chart, why? |
0 replies
|
I have so many questions, here's some of them:
|
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment




Uh oh!
There was an error while loading. Please reload this page.
Hello WinUI community!
Sometimes a dashboard needs a simple answer: how is the business doing? A line can reveal a trend. A pair of columns can show whether revenue is keeping ahead of expenses. A well-placed label can explain the month that changed everything.
You have asked for a native way to build these experiences, including in #11017, Is there a good charting library for WinUI?.
Windows App SDK 2.5.4-experimental includes
Chart, a first-party control in theMicrosoft.UI.Xaml.Controls.Chartsnamespace. It brings line, area and bar series, category and date-time axes, numeric value axes, legends, data labels and markers to your WinUI 3 app.This is an experimental release. Use it to explore and prototype, and expect APIs to change before the control becomes stable.
A dashboard that tells a story
Meet Contoso Finance, a showcase for a small design studio's business finances and personal savings. Its overview pairs four KPI cards with charts for revenue and expenses, cash balance, an investment portfolio and spending by category.
The KPI cards and navigation use standard WinUI controls. The charts turn the illustrative financial data into comparisons and trends. Calculations such as savings rate, cash runway and category totals belong to the app, not the chart control.
The deeper views use the same building blocks: columns for cash flow, a line for cash on hand, a filled area for portfolio value and horizontal bars for spending.
📊 Compare revenue and expenses
A chart starts with a
Chartelement and its series. Two verticalBarSeriesgive us a side-by-side monthly comparison.Here is the chart from the minimal sample below. The
chartsprefix maps toMicrosoft.UI.Xaml.Controls.Charts:Each series has an X data slot and a Y data slot. For this chart, month names use a
CategoryAxisand dollar amounts use aLinearAxis. Add the axes toChart.Axesbefore assigning them to the series; both series can share them.Samplessupplies one dimension's values. These examples useList<string>for categories,List<double>for amounts and, later,List<DateTimeOffset>for dates. Keep the X and Y lists aligned so each category has its corresponding amount.For the series in this release, use a
CategoryAxisorDateTimeAxisin the X slot and aLinearAxisin the Y slot. Those are data roles: with horizontal bars, the category slot is drawn vertically.🎯 Make the important point stand out
Most charts have a point the reader should notice first. On the cash-balance view, April's tax payment gets a red triangle and August's record balance gets an orange diamond. A separate dashed line marks the safety floor.
DataLabelOverridesandDataMarkerOverridescustomize individual points by zero-based index. WithCashreferring to the line series and January at index 0:These are labels and markers drawn on the chart, not hover tooltips. Use
ShowDataLabelsandShowDataMarkersfor the rest of the series. There are nine visible marker shapes, including circles, triangles, diamonds and dashes, plusNone.The spending view uses a label override to call out payroll's share of total spend. The app prepares the ranked categories and calculates the percentage; Chart presents the result.
If you replace or reorder a series' data, update its overrides too: index 3 means the fourth point in the new data, not a permanently identified transaction.
🗓️ Put time on the X axis
For portfolio history, use an
AreaSerieswith aDateTimeAxis. Supply dates asDateTimeOffsetvalues and amounts as doubles.LabelFormataccepts a WindowsDateTimeFormatterformat string.This example uses one prepared value per month. After creating
Portfolio, addingtimetoPortfolioChart.Axes, and assigning it toPortfolio.XAxis, the setup is:IntervalTypeoffers Auto, Day, Week, Month and Year. Choose an interval appropriate to the data you supply; changing it does not calculate financial aggregates such as a monthly closing balance. The example applies its interval and label format when the chart loads.The dashboard's 6M / 1Y / 5Y views illustrate how the same charts can tell different stories as the time window changes. The straightforward update path used here is to build replacement lists and assign new
Samplesobjects to the series.For this experimental C# sample, use that explicit replacement path rather than assuming an in-place collection change will automatically redraw the chart.
🌗 At home in light and dark
Merge
XamlChartsResourcesalongsideXamlControlsResourcesinApp.xamlto supply the chart's styles and theme resources. Axis lines, grid lines and text follow the app theme.You can also set series
Strokeand, for bars and areas,Fillto customize their colors. Contoso Finance uses lighter series colors in its dark presentation. When you supply custom brushes, account for both themes rather than assuming a fixed color will adapt automatically. A transparent chart background lets the surrounding card show through.Try it out
Install Microsoft.WindowsAppSDK 2.5.4-experimental, read the release notes and explore the experimental Charts API reference.
For this release, the sample below uses
WindowsAppSDKSelfContained=trueto avoid the framework-dependent resource lookup issue reported in #12115. Its setup also includes both resource dictionaries.Start building: a minimal finance chart
Start with one view of the same finance scenario: six months of revenue and expenses, with a button to switch themes. This is the minimal sample application, not the full Contoso Finance showcase.
Create a blank WinUI 3 app named
FinanceChartswith Microsoft.WindowsAppSDK 2.5.4-experimental. Keep the template'sApp.xaml.cs, which creates and activatesMainWindow. If using another project name, updatex:Classand the C# namespace to match.Add this property to the project's
PropertyGroup:Merge both resource dictionaries in
App.xaml:Replace the two window files with the complete code below, then build and run with Debug | x64.
MainWindow.xaml
MainWindow.xaml.cs
💬 Tell us what you think
Put Chart in an app and tell us where it helps and where you need more. Share your experience in WinUI discussions or file an issue.
Team WinUI
All reactions