Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

wpf graph: fix width of vertical axis

Solved!
Go to solution

How do I do that? Currently it's resized automatically to fit max tick label.

0 Kudos
Message 1 of 9
(8,169 Views)

Hi EugeneM,

 

Can you post a picture of what you're seeing, and what you'd like instead? I'm not sure that I understand.

 

Thanks!

 

Alexandra

National Instruments
Applications Engineer
0 Kudos
Message 2 of 9
(8,155 Views)

I need to fix width of selected area. Currently it depends on max length of numbers on the axis, e.g. if max value will be 1000.00 instead of 30.00 then axis will become wider...

0 Kudos
Message 3 of 9
(8,151 Views)

Hi EugeneM,

 

According to this help page about the minimum width property, the graph will always expand to fit the largest value on the axis.

 

Regards,

 

Alexandra

 

National Instruments
Applications Engineer
0 Kudos
Message 4 of 9
(8,142 Views)

it seems to me that this reference is for WF graphs, not WPF, so it's not relevant

0 Kudos
Message 5 of 9
(8,132 Views)

Hi EugeneM,

 

Whoops! The WPF also does not have an explicit property to set the width of the axis. You can change the visibility of the labels, and their orientation, which may help you with your space concerns.

 

What exactly are you trying to accomplish?

 

Regards,


Alexandra

National Instruments
Applications Engineer
0 Kudos
Message 6 of 9
(8,117 Views)

As Alex+ra mentioned, you can customize the LabelVisibility or LabelOrientation properties on the MajorDivisions of the vertical axis to change how the default labels are displayed. You can also customize the LabelPresenter, using a fixed-width format or using a custom formatter that provides fixed-width labels:


    <ni:AxisDouble Range="0,1000">
        <ni:AxisDouble.MajorDivisions>
            <ni:RangeLabeledDivisions LabelOrientation="Perpendicular" />
        </ni:AxisDouble.MajorDivisions>
    </ni:AxisDouble>

    <ni:AxisDouble Range="0,1000">
        <ni:AxisDouble.MajorDivisions>
            <ni:RangeLabeledDivisions LabelPresenter="G1" />
        </ni:AxisDouble.MajorDivisions>
    </ni:AxisDouble>

    <ni:AxisDouble Range="0,1000">
        <ni:AxisDouble.MajorDivisions>
            <ni:RangeLabeledDivisions>
                <ni:RangeLabeledDivisions.LabelPresenter>
                    <ni:TemplateValuePresenter>
                        <ni:TemplateValuePresenter.Template>
                            <DataTemplate>
                                <Viewbox MaxWidth="16" StretchDirection="DownOnly">
                                    <TextBlock Text="{Binding}" />
                                </Viewbox>
                            </DataTemplate>
                        </ni:TemplateValuePresenter.Template>
                    </ni:TemplateValuePresenter>
                </ni:RangeLabeledDivisions.LabelPresenter>
            </ni:RangeLabeledDivisions>
        </ni:AxisDouble.MajorDivisions>
    </ni:AxisDouble>


FixedWidthVerticalAxis.png

~ Paul H
0 Kudos
Message 7 of 9
(8,105 Views)

Hi, Paul!

 

This is much better. Now the only question is how do I combine this with ValueFormatter override? LabelPresenter doesn't allow to have both GeneralValueFormatter and TemplateValuePresenter...

 

<ni:RangeLabeledDivisions.LabelPresenter>
<!--ni:GeneralValueFormatter Format="0.00" /-->
<ni:TemplateValuePresenter>
<ni:TemplateValuePresenter.Template>
<DataTemplate>
<Viewbox Width="41" Stretch="None" HorizontalAlignment="Right" Margin="0,0,5,0">
<TextBlock Text="{Binding}" />
</Viewbox>
</DataTemplate>
</ni:TemplateValuePresenter.Template>
</ni:TemplateValuePresenter>
</ni:RangeLabeledDivisions.LabelPresenter>

0 Kudos
Message 8 of 9
(8,102 Views)
Solution
Accepted by topic author eugenem

I just used TemplateValuePresenter as an easy XAML-only example. When you define your own value formatter, you can return whatever UI element you want to display. For example, if you were deriving from GeneralValueFormatter, you could use code like below to wrap its visual in a Viewbox:


    protected override UIElement VisualizeCore<TData>( TData value, ValuePresenterArgs args, UIElement existingVisual ) {
        var viewbox =
               existingVisual as Viewbox
            ?? new Viewbox { MaxWidth = 16, StretchDirection = StretchDirection.DownOnly };

        viewbox.Child = base.VisualizeCore<TData>( value, args, viewbox.Child );
        return viewbox;
    }




From your XAML snippet though, it looks like you just want to specify a .NET "0.00" format. In that case, you can use the StringFormat property provided by Binding:


    <TextBlock Text="{Binding StringFormat=0.00}" />

~ Paul H
Message 9 of 9
(8,098 Views)