A ProEssentials v10 WPF .NET 8 demonstration of two distinct approaches
to replacing the default numeric Y-axis labels with custom text — shown
side-by-side in a single PesgoWpf chart split into two stacked
multi-axis sections.
A single PesgoWpf chart with two independent Y-axis sections, each
using a different technique to display custom Y-axis labels:
| Section | Approach | Best For |
|---|---|---|
| Top | Line Annotation Grid Lines | Fixed labels known at design time |
| Bottom | PeCustomGridNumber Event |
Dynamic labels — works after zoom/scroll |
Two subsets share one chart but each gets its own independent Y-axis
section via MultiAxesSubsets:
Pesgo1.PeGrid.MultiAxesSubsets[0] = 1; // top section — subset 0
Pesgo1.PeGrid.MultiAxesSubsets[1] = 1; // bottom section — subset 1
Pesgo1.PeGrid.OverlapMultiAxes[0] = 1; // top = 1 axis group (not overlapped)
Pesgo1.PeGrid.OverlapMultiAxes[1] = 1; // bottom = 1 axis group
Pesgo1.PeGrid.MultiAxesProportions[0] = 0.5f;
Pesgo1.PeGrid.MultiAxesProportions[1] = 0.5f;
Pesgo1.PeGrid.Option.MultiAxisStyle = MultiAxisStyle.SeparateAxes;
Pesgo1.PeGrid.Option.MultiAxesSeparators = MultiAxesSeparators.Medium;
// End-user can drag the separator to resize sections
Pesgo1.PeUserInterface.Allow.MultiAxesSizing = true;WorkingAxis selects which axis subsequent property assignments apply to.
Always reset to 0 when finished configuring axes.
The default numeric Y scale is hidden and replaced by LineAnnotationType.GridLine
and GridTick annotations:
Pesgo1.PeGrid.WorkingAxis = 0;
// Hide the default numeric scale
Pesgo1.PeGrid.Option.ShowYAxis = ShowAxis.Empty;
// Fix the range so annotation values land at meaningful positions
Pesgo1.PeGrid.Configure.ManualScaleControlY = ManualScaleControl.MinMax;
Pesgo1.PeGrid.Configure.ManualMinY = 0.0;
Pesgo1.PeGrid.Configure.ManualMaxY = 1500.0;
// Annotations targeted to axis 0 via YAxisAxis[i]
Pesgo1.PeAnnotation.Line.YAxisAxis[0] = 0;
Pesgo1.PeAnnotation.Line.YAxis[0] = 200;
Pesgo1.PeAnnotation.Line.YAxisType[0] = LineAnnotationType.GridLine;
Pesgo1.PeAnnotation.Line.YAxisText[0] = "|LLow Value";
// ... more GridLine and GridTick entries ...
Pesgo1.PeAnnotation.Line.LeftMargin = "Medium Value "; // longest label
Pesgo1.PeAnnotation.Show = true;
Pesgo1.PeFont.LineAnnotationTextSize = 100;YAxisAxis[i] = 0 is what makes annotations appear only in the top
axis region. Without it, annotations default to axis 0, but setting it
explicitly is required for multi-axis correctness and clarity.
GridTick adds intermediate tick marks without a label — useful for
subdividing the range between labeled gridlines.
Trade-off: label values must be known at design time. If the user zooms, new intermediate values appear as unlabeled numbers.
CustomGridNumbersY = true is set while WorkingAxis = 1 so it applies
only to the bottom axis:
Pesgo1.PeGrid.WorkingAxis = 1;
Pesgo1.PeGrid.Option.CustomGridNumbersY = true;The PeCustomGridNumber event fires for each grid line during image
construction. The handler checks e.AxisIndex (1 = bottom axis) and
e.AxisType (0 = left Y) before rewriting e.NumberString:
private void Pesgo1_PeCustomGridNumber(object sender,
Gigasoft.ProEssentials.EventArg.CustomGridNumberEventArgs e)
{
if (e.AxisIndex != 1 || e.AxisType != 0) return;
int level = (int)Math.Round(Math.Abs(e.NumberValue));
e.NumberString = e.NumberValue >= 0
? $"+ {level}"
: $"− {level}";
}Trade-off: slightly more code, but works correctly after any zoom or scroll because the event fires fresh for whatever values appear on screen.
Warning: do not place breakpoints inside this event handler. It fires during
WM_PAINTprocessing; a breakpoint can trigger a recursive paint. UseDebug.WriteLineor trace logging instead.
Axis label and grid number colors are synced to subset data colors so the user can visually associate each Y axis with its data line:
Pesgo1.PeGrid.WorkingAxis = 0;
Pesgo1.PeColor.YAxis = ColorTop; // cyan
Pesgo1.PeColor.SubsetColors[0] = ColorTop;
Pesgo1.PeGrid.WorkingAxis = 1;
Pesgo1.PeColor.YAxis = ColorBottom; // orange
Pesgo1.PeColor.SubsetColors[1] = ColorBottom;| Input | Action |
|---|---|
| Left-click drag | Zoom box |
| Drag separator | Resize top / bottom sections |
| Right-click | Context menu — export, print, customize |
- Visual Studio 2022
- .NET 8 SDK
1. Clone this repository
2. Open CustomYAxisLabeling.sln in Visual Studio 2022
3. Build → Rebuild Solution (NuGet restore is automatic)
4. Press F5
References
ProEssentials.Chart.Net80.x64.Wpf.
Package restore is automatic on build.
- WPF Heatmap Spectrogram
- Financial OHLC — Trading Signals
- All Examples — GigasoftInc on GitHub
- Full Evaluation Download
- gigasoft.com
Example code is MIT licensed. ProEssentials requires a commercial license for continued use.
