Skip to content

Add Chart samples - #2256

Closed
Nitin Chaudhary (Nitin-100) wants to merge 4 commits into
microsoft:mainfrom
Nitin-100:user/nitchaudhary/chart-samples
Closed

Nitin Chaudhary (Nitin-100) wants to merge 4 commits into
microsoft:mainfrom
Nitin-100:user/nitchaudhary/chart-samples

Conversation

@Nitin-100

@Nitin-100 Nitin Chaudhary (Nitin-100) commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds a Chart page (Media, experimental) for Microsoft.UI.Xaml.Controls.Charts, which ships in Windows App SDK 2.5.4-experimental (WinUI 2.3.10-experimental). Credit to Morten Nielsen (@dotMorten): this builds on his user/dotmorten/charts commit ("Add charting samples"), rebased onto current main. His commit is preserved as the first commit.

The page follows AGENTS.md: a copyable App.xaml setup snippet first, then one idea per example.

Example Covers
Create a line chart with axes and a legend Samples, Chart.Data/Axes/Series, CategoryAxis, LinearAxis, LineSeries, ShowLegend, LegendTitle
Create a bar chart and sort its categories BarSeries.Orientation, CategoryAxis.SortKey, SortOrder
Configure axes LinearAxis.Minimum/Maximum/Spacing, GridLines (None/Major/Minor), Axis.IsVisible, ShowTickLabels, ShowTickMarks, AxisLineBrush, TickBrush, GridLineMajorBrush, GridLineMinorBrush
Combine area, bar, and line series Shared axes, legend entries, CartesianSeries.IsVisible, Fill, Stroke, StrokeDashStyle, MarkerShape
Customize lines, markers, and data labels All StrokeDashStyle and MarkerShape values, StrokeThickness, ShowDataMarkers, ShowDataLabels, DataLabelOverrides, DataMarkerOverrides
Plot a time series Chart built in code, DateTimeAxis.Minimum/Maximum/IntervalType/LabelFormat
Update a series data source Samples.ItemsSource bound to an ObservableCollection<double>

Other changes:

  • Known Chart control issue (worked around in the samples). BarSeries.Orientation defaults to Horizontal. A horizontal BarSeries that shares a CategoryAxis X axis with an area or line series leaves its chart blank. It also stops other charts on the same page from drawing (only the legend title renders), even if the affected chart is collapsed. The samples set Orientation explicitly on every BarSeries, a test enforces it, and the bar example explains the default. This needs a fix in the control; I can file it with the Charts owners.
  • Theme-safe colors. Chart properties reject {ThemeResource} (XamlParseException: Failed to assign to property), and a nested SolidColorBrush Color="{ThemeResource …}" doesn't follow a later theme switch. The samples rely on the control's theme-aware defaults for text and labels, and use fixed series colors that keep at least 3:1 contrast in both themes. The previous black data label disappeared in dark theme.
  • Option handlers apply changes only after the page loads. Initial values are declared in markup, so the published catalog XAML matches what the gallery renders.
  • ControlInfoData.json: new Chart.png control image (it previously used Placeholder.png), Learn API doc links, more search tags, and an updated description.
  • Listed under Media, next to InkCanvas / InkToolbar (per review).
  • catalog/windows-samples.json regenerated.

Motivation and Context

Chart is the third experimental control in 2.5.x, after TableView (#2250) and InkCanvas/InkToolbar (#2245, #2247), and it has no gallery page yet. This covers the whole public Charts API surface. The list was taken from the 2.3.10-experimental winmd so no member is missed.

How Has This Been Tested?

Windows 11 x64, Debug, .NET SDK 9.0.318 (app) and 10.0.401 (catalog tools).

  • dotnet build WinUIGallery\WinUIGallery.csproj -c Debug -p:Platform=x64 -p:BuildAllAppFlavors=false -p:AppxBundle=Never: builds with no new warnings.
  • dotnet run --project tools\CatalogExporter -- generate, then check: index up to date (126 controls, 348 samples). All seven Chart samples publish well-formed XAML with no unresolved $(…) tokens.
  • dotnet test tests\WinUIGallery.CatalogExporter.Tests: 166/166 pass, including the new ChartSamplesTests:
    • The setup snippet is copyable and comes before the examples.
    • App.xaml merges XamlChartsResources after XamlControlsResources.
    • Example headers and snippets are checked, and the initial option values are published.
    • API coverage: a test fails if a sample stops demonstrating a Charts member.
    • Every BarSeries sets Orientation.
    • No {ThemeResource} on chart properties.
    • The last two guards were mutation-checked: each fails when the problem is reintroduced.
  • dotnet format --verify-no-changes is clean on the new page and test files. git diff --check is clean.
  • Ran the packaged app on the Chart page:
    • Axe.Windows scan (same rules and global exclusions as AxeScanAllTests): 0 errors. No page-specific exclusion is needed.
    • Drove every option through UI Automation, and the app stayed responsive throughout: legend, orientation, sort key and order, all grid-line modes, axis/tick toggles, series visibility, all 5 dash styles, all 9 marker shapes, thickness, marker/label toggles, all interval types and label formats, and live add/remove.
    • Checked all seven charts in light and dark theme.

Screenshots

Captured before the move to Media, so the navigation pane still shows Chart under Collections.

1-line-light 2-bar-horizontal-sorted-and-axes-minor 3-axes-and-combined-light 4-series-hidden-and-dashdot-triangle 5-lines-and-timeseries-day 6-live-light 7-combined-dark 8-line-bar-dark

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
Builds on dotMorten's "Add charting samples" (user/dotmorten/charts), rebased onto
current main.

- Fix: BarSeries.Orientation defaults to Horizontal. A horizontal BarSeries sharing a
  CategoryAxis X axis left its chart blank and stopped other charts on the page from
  drawing. Every BarSeries now sets Orientation explicitly.
- Add App.xaml setup snippet for XamlChartsResources (copyable, like TableView).
- Add examples for axis configuration (IsVisible, tick labels/marks, grid lines,
  brushes), bar orientation and CategoryAxis sorting, series visibility, line dash
  styles, marker shapes, stroke thickness, data labels/markers with per-point
  overrides, and DateTimeAxis Minimum/Maximum/IntervalType/LabelFormat.
- Replace brushes that were unreadable in dark theme; rely on the control's theme-aware
  defaults for labels and text.
- Add Chart control image and Learn API doc links.
- Add ChartSamplesTests (setup snippet, App.xaml order, examples, initial values, API
  coverage, BarSeries orientation, no ThemeResource on chart properties).
- Regenerate catalog/windows-samples.json.

Co-authored-by: Morten Nielsen <mn@iter.dk>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Nitin-100

Copy link
Copy Markdown
Contributor Author

/azp run

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pranav-gupta-msft

Copy link
Copy Markdown
Member

This will not go in collections but media

Per review feedback, list Chart under Media instead of Collections and regenerate
catalog/windows-samples.json.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Nitin-100

Copy link
Copy Markdown
Contributor Author

/azp run

1 similar comment
@Nitin-100

Copy link
Copy Markdown
Contributor Author

/azp run

@niels9001
Niels Laute (niels9001) enabled auto-merge (squash) October 7, 2026 10:10
@Nitin-100 Nitin Chaudhary (Nitin-100) mentioned this pull request Oct 7, 2026
1 of 3 tasks
@Nitin-100

Copy link
Copy Markdown
Contributor Author

Superseded by #2261, which is the same change from a branch in this repo instead of my fork, with the latest main merged in. Pranav Gupta (@pranav-gupta-msft), your Media feedback is included there. Could you re-approve on #2261? Closing this one.

auto-merge was automatically disabled October 7, 2026 11:11

Pull request was closed

Niels Laute (niels9001) added a commit that referenced this pull request Oct 7, 2026
> Replaces #2256, which was opened from a fork. Same commits, plus the
latest `main` merged in. @pranav-gupta-msft's review feedback (move
Chart to Media) is included.

## Description
Adds a **Chart** page (Media, experimental) for
`Microsoft.UI.Xaml.Controls.Charts`, which ships in Windows App SDK
2.5.4-experimental (WinUI 2.3.10-experimental). Credit to @dotMorten:
this builds on his `user/dotmorten/charts` commit ("Add charting
samples"), rebased onto current `main`. His commit is preserved as the
first commit.

The page follows `AGENTS.md`: a copyable App.xaml setup snippet first,
then one idea per example.

| Example | Covers |
|---|---|
| Create a line chart with axes and a legend | `Samples`,
`Chart.Data`/`Axes`/`Series`, `CategoryAxis`, `LinearAxis`,
`LineSeries`, `ShowLegend`, `LegendTitle` |
| Create a bar chart and sort its categories | `BarSeries.Orientation`,
`CategoryAxis.SortKey`, `SortOrder` |
| Configure axes | `LinearAxis.Minimum`/`Maximum`/`Spacing`, `GridLines`
(None/Major/Minor), `Axis.IsVisible`, `ShowTickLabels`, `ShowTickMarks`,
`AxisLineBrush`, `TickBrush`, `GridLineMajorBrush`, `GridLineMinorBrush`
|
| Combine area, bar, and line series | Shared axes, legend entries,
`CartesianSeries.IsVisible`, `Fill`, `Stroke`, `StrokeDashStyle`,
`MarkerShape` |
| Customize lines, markers, and data labels | All `StrokeDashStyle` and
`MarkerShape` values, `StrokeThickness`, `ShowDataMarkers`,
`ShowDataLabels`, `DataLabelOverrides`, `DataMarkerOverrides` |
| Plot a time series | Chart built in code,
`DateTimeAxis.Minimum`/`Maximum`/`IntervalType`/`LabelFormat` |
| Update a series data source | `Samples.ItemsSource` bound to an
`ObservableCollection<double>` |

Other changes:
- **Known Chart control issue (worked around in the samples).**
`BarSeries.Orientation` defaults to `Horizontal`. A horizontal
`BarSeries` that shares a `CategoryAxis` X axis with an area or line
series leaves its chart blank. It also stops *other* charts on the same
page from drawing (only the legend title renders), even if the affected
chart is collapsed. The samples set `Orientation` explicitly on every
`BarSeries`, a test enforces it, and the bar example explains the
default. This needs a fix in the control; I can file it with the Charts
owners.
- **Theme-safe colors.** Chart properties reject `{ThemeResource}`
(`XamlParseException: Failed to assign to property`), and a nested
`SolidColorBrush Color="{ThemeResource …}"` doesn't follow a later theme
switch. The samples rely on the control's theme-aware defaults for text
and labels, and use fixed series colors that keep at least 3:1 contrast
in both themes. The previous black data label disappeared in dark theme.
- Option handlers apply changes only after the page loads. Initial
values are declared in markup, so the published catalog XAML matches
what the gallery renders.
- `ControlInfoData.json`: new `Chart.png` control image (it previously
used `Placeholder.png`), Learn API doc links, more search tags, and an
updated description.
- Listed under **Media**, next to InkCanvas / InkToolbar (per review).
- `catalog/windows-samples.json` regenerated.

## Motivation and Context
Chart is the third experimental control in 2.5.x, after TableView
(#2250) and InkCanvas/InkToolbar (#2245, #2247), and it has no gallery
page yet. This covers the whole public Charts API surface. The list was
taken from the 2.3.10-experimental winmd so no member is missed.

## How Has This Been Tested?
Windows 11 x64, Debug, .NET SDK 9.0.318 (app) and 10.0.401 (catalog
tools).

- `dotnet build WinUIGallery\WinUIGallery.csproj -c Debug
-p:Platform=x64 -p:BuildAllAppFlavors=false -p:AppxBundle=Never`: builds
with no new warnings.
- `dotnet run --project tools\CatalogExporter -- generate`, then
`check`: index up to date (126 controls, 349 samples). All seven Chart
samples publish well-formed XAML with no unresolved `$(…)` tokens.
- `dotnet test tests\WinUIGallery.CatalogExporter.Tests`: **166/166
pass**, including the new `ChartSamplesTests`:
  - The setup snippet is copyable and comes before the examples.
- `App.xaml` merges `XamlChartsResources` after `XamlControlsResources`.
- Example headers and snippets are checked, and the initial option
values are published.
- API coverage: a test fails if a sample stops demonstrating a Charts
member.
  - Every `BarSeries` sets `Orientation`.
  - No `{ThemeResource}` on chart properties.
- The last two guards were mutation-checked: each fails when the problem
is reintroduced.
- `dotnet format --verify-no-changes` is clean on the new page and test
files. `git diff --check` is clean.
- Ran the packaged app on the Chart page:
- **Axe.Windows** scan (same rules and global exclusions as
`AxeScanAllTests`): **0 errors**. No page-specific exclusion is needed.
- Drove every option through UI Automation, and the app stayed
responsive throughout: legend, orientation, sort key and order, all
grid-line modes, axis/tick toggles, series visibility, all 5 dash
styles, all 9 marker shapes, thickness, marker/label toggles, all
interval types and label formats, and live add/remove.
  - Checked all seven charts in light and dark theme.

## Screenshots
_Captured before the move to Media, so the navigation pane still shows
Chart under Collections._

<img width="975" height="813" alt="1-line-light"
src="https://github.com/user-attachments/assets/ac29ef29-2b71-45e9-b4d0-bbfe1a4468be"
/>
<img width="975" height="813"
alt="2-bar-horizontal-sorted-and-axes-minor"
src="https://github.com/user-attachments/assets/2fb29d05-3015-48a1-824d-a29ed4a5b496"
/>
<img width="975" height="813" alt="3-axes-and-combined-light"
src="https://github.com/user-attachments/assets/0c53588d-2aee-4b7a-bf4b-d754af264169"
/>
<img width="975" height="813" alt="4-series-hidden-and-dashdot-triangle"
src="https://github.com/user-attachments/assets/4823eb36-b326-42a1-849e-a9aff544036f"
/>
<img width="975" height="813" alt="5-lines-and-timeseries-day"
src="https://github.com/user-attachments/assets/249c20a4-060e-4471-9f7a-fd50d5a28ad1"
/>
<img width="975" height="813" alt="6-live-light"
src="https://github.com/user-attachments/assets/edd4a881-fb2c-4e22-a749-8a0d6fc618d2"
/>
<img width="975" height="813" alt="7-combined-dark"
src="https://github.com/user-attachments/assets/a8bafeda-603f-4a85-b452-d106e4a9a3b5"
/>
<img width="975" height="813" alt="8-line-bar-dark"
src="https://github.com/user-attachments/assets/333433ca-68c3-45c1-8a27-f8df5a01659c"
/>

## Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

---------

Co-authored-by: Morten Nielsen <mn@iter.dk>
Co-authored-by: Nitin Chaudhary <nitchaudhary@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Niels Laute <nielslaute@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants