03-24-2016 10:54 PM
I would like to know how to set a margin between major tick marks and their labels in a WPF Graph.
Especially in the YAxis, labels are placed very close to the ticks.
Solved! Go to Solution.
03-25-2016 10:42 AM
Unfortunately, there is no existing configuration property to add extra space around scale labels. I have created a task to address this in a future Measurement Studio release.
As a workaround, you can use a string format that includes additional whitespace in the result:
<ni:AxisDouble Orientation="Vertical" ...>
<ni:AxisDouble.MajorDivisions>
<ni:RangeLabeledDivisions>
<ni:RangeLabeledDivisions.LabelPresenter>
<ni:GeneralValueFormatter Format="{}{0} " />
</ni:RangeLabeledDivisions.LabelPresenter>
</ni:RangeLabeledDivisions>
</ni:AxisDouble.MajorDivisions>
</ni:AxisDouble>
If you need finer control, you can create a custom label presenter to add additional space to the generated label visual.
03-27-2016 08:11 PM - edited 03-27-2016 08:26 PM
Paul, thanks for your kind reply.
By adding "VisualizeCore" method into your EngineeringValueFormatter class, I can do what I want.
class EngineeringValueFormatter: ValueFormatter { ... protected override UIElement VisualizeCore<TData>(TData value, ValuePresenterArgs args, UIElement existingVisual) { UIElement element = base.VisualizeCore<TData>(value, args, existingVisual); // Add additional space to the generated label visual. var axis = (Axis<TData>)args.Context; var tb = (TextBlock)element; if (axis.Orientation == Orientation.Vertical) { if (axis.Location == RelativeLocation.Near) tb.Margin = new Thickness(0, 0, 5, 0); else if (axis.Location == RelativeLocation.Far) tb.Margin = new Thickness(5, 0, 0, 0); } else if (axis.Orientation == Orientation.Horizontal) { if (axis.Location == RelativeLocation.Near) tb.Margin = new Thickness(0, 0, 0, 0); else if (axis.Location == RelativeLocation.Far) tb.Margin = new Thickness(0, 0, 0, 5); } return element; } }
07-08-2019 04:33 PM
Just wanted to let you know that value formatters now include a Padding
property (although admittedly not as flexible as your custom code!):
<ni:AxisDouble.MajorDivisions> <ni:RangeLabeledDivisions> <ni:GeneralValueFormatter Padding="0,0,5,0" /> </ni:RangeLabeledDivisions> </ni:AxisDouble.MajorDivisions>