Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Graph Name and Legend color settings

Solved!
Go to solution

Hello, I have three questions... (WPF C#)

  1. Is there a way to give this Graph a name w/out creating a separate label?
  2. How can I change the Legend Foreground color to White?  I mean, I changed Foreground to White but it's still black as you can see.
  3. How can I cnange the Axis color to White?

 

Thank you!

Capture.PNG

 

0 Kudos
Message 1 of 15
(6,234 Views)

1. A separate label is the expected way to associate a control with a descriptive name.



2. The default template for plot labels in the Legend uses a TextBox, which appears to override Foreground in its default style. An easy workaround is to specify a custom label template:


    <DataTemplate x:Key="PlotLabelTemplate">
        <TextBlock Text="{Binding}" />
    </DataTemplate>

    ...

    <ni:Plot Label="Plot 1" LabelTemplate="{StaticResource PlotLabelTemplate}" />



3. In your screenshot, the axis ticks and labels already match the foreground, so I assume by "Axis color" you mean the baseline color? In that case, you can set the BaselineStroke property:


    <ni:AxisDouble Orientation="Vertical" BaselineStroke="White" />

~ Paul H
0 Kudos
Message 2 of 15
(6,225 Views)

Thank you.  I got #1 and #3 but can't make #2 work.

This is my XAML code (I generate Plots programatically in C#).

Could you please help?

 

<DockPanel x:Name="Vco1Graph" Visibility="Visible">
                                            <Grid DockPanel.Dock="Top">
                                                <ni:GraphInteractionPalette Graph="{Binding ElementName=GraphVCO1}" Margin="50,0,0,0"/>
                                                <Label Content="VCO__1" HorizontalAlignment="Center" Style="{DynamicResource EvolvDiagsLabel}"/>
                                            </Grid>
                                            <ni:Legend ItemsSource="{Binding AllPlots, ElementName=GraphVCO1}" DockPanel.Dock="Right" Width="90" IsTabStop="False"
ItemBackground="{DynamicResource ColorSolidReadOnlyBackground}"
BorderBrush="{Binding BorderBrush, ElementName=GraphVCO1}"
Background="{DynamicResource ColorSolidReadOnlyBackground}"
Foreground="{DynamicResource ColorSolidNormalForeground}"/> <ni:Graph x:Name="GraphVCO1" DockPanel.Dock="Top" HorizontalAlignment="Left" Width="877"
PlotAreaBackground="{DynamicResource ColorSolidReadOnlyBackground}"
PlotAreaBorderBrush="{DynamicResource ColorSolidReadOnlyBackground}"> <ni:Graph.Plots> <ni:Plot/> </ni:Graph.Plots> <ni:Graph.Axes> <ni:AxisDouble Orientation="Vertical" BaselineStroke="{DynamicResource ColorSolidNormalForeground}"> <ni:AxisDouble.LabelTemplate> <DataTemplate> <Label Content="dB" Foreground="{DynamicResource ColorSolidNormalForeground}"/> </DataTemplate> </ni:AxisDouble.LabelTemplate> <ni:AxisDouble.MajorGridLines> <ni:GridLines Stroke="{DynamicResource ColorSolidNormalForeground}" StrokeThickness="0.3"/> </ni:AxisDouble.MajorGridLines> </ni:AxisDouble> <ni:AxisDouble Orientation="Horizontal" Adjuster="FitExactly" BaselineStroke="{DynamicResource ColorSolidNormalForeground}"> <ni:AxisDouble.LabelTemplate> <DataTemplate> <Label Content="GHz" Foreground="{DynamicResource ColorSolidNormalForeground}"/> </DataTemplate> </ni:AxisDouble.LabelTemplate> <ni:AxisDouble.MajorGridLines> <ni:GridLines Stroke="{DynamicResource ColorSolidNormalForeground}" StrokeThickness="0.3"/> </ni:AxisDouble.MajorGridLines> </ni:AxisDouble> </ni:Graph.Axes> </ni:Graph> </DockPanel>

 

0 Kudos
Message 3 of 15
(6,219 Views)

Since you are generated plots in code, it may make more sense for you to override the default legend template for plots instead:


    <DataTemplate DataType="{x:Type ni:Plot}">
        <StackPanel Orientation="Horizontal">
            <niPrimitives:LegendGlyph Margin="3"
                    Renderer="{Binding ActualRenderer}"
                    Background="{Binding ItemBackground, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}"
                    Width="{Binding GlyphSize.Width, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}"
                    Height="{Binding GlyphSize.Height, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" />

            <ContentPresenter Margin="3"
                    VerticalAlignment="Center"
                    Content="{Binding Label}" />
        </StackPanel>
    </DataTemplate>

~ Paul H
0 Kudos
Message 4 of 15
(6,214 Views)

Thanks but it's still not clear when I have ti insert this chunk of code.  No matter what I try I get errors.

0 Kudos
Message 5 of 15
(6,211 Views)

Sorry for not specifying that before. It should go in the Resources for the legend (or in Resources higher up). For example:


    <ni:Legend ItemsSource="{Binding ...}" ...>
        <ni:Legend.Resources>
            <DataTemplate DataType="{x:Type ni:Plot}">
                ...
            </DataTemplate>
        </ni:Legend.Resources>
    </ni:Legend>

~ Paul H
0 Kudos
Message 6 of 15
(6,202 Views)

 

Still no luck... I get:

"Error 1 The name "Plot" does not exist in the namespace "http://schemas.ni.com/controls/2009/xaml/presentation"

 

                                        <DockPanel>
                                            <Grid>
                                                <ni:GraphInteractionPalette Graph="{Binding ElementName=GraphVCO1}"/>
                                            </Grid>
                                            <ni:Legend ItemsSource="{Binding AllPlots, ElementName=GraphVCO1}">
                                                <ni:Legend.Resources>
                                                    <DataTemplate DataType="{x:Type ni:Plot}">
                                                        <StackPanel Orientation="Horizontal">
                                                            <niPrimitives:LegendGlyph Margin="3" 
                                                                Renderer="{Binding ActualRenderer}" 
                                                                Background="{Binding ItemBackground, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" 
                                                                Width="{Binding GlyphSize.Width, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" 
                                                                Height="{Binding GlyphSize.Height, RelativeSource={RelativeSource AncestorType={x:Type ni:Legend}, Mode=FindAncestor}}" />

                                                            <ContentPresenter Margin="3" VerticalAlignment="Center" Content="{Binding Label}"/>
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </ni:Legend.Resources>
                                            </ni:Legend>
                                            <ni:Graph x:Name="GraphVCO1"
                                                <ni:Graph.Plots>
                                                    <ni:Plot/>
                                                </ni:Graph.Plots>
                                            </ni:Graph>
                                        </DockPanel>

 

0 Kudos
Message 7 of 15
(6,178 Views)

If you're in Visual Studio 2013 then you'll need to create a .licx file as outlined here: http://digital.ni.com/public.nsf/allkb/C51E3B38578FAD2786257C070069F386. That error can be caused by not having an licx file.

 

Kevin

0 Kudos
Message 8 of 15
(6,166 Views)

I already solved the licx issue last week and have been able to do eveyrhting since then.  I just want to change the color of the Legend labels

0 Kudos
Message 9 of 15
(6,164 Views)

Unfortunately, I could not reproduce the issue you are seeing. It seems particularly odd since you declare a <ni:Plot/> later on in your example.


Since the schema-based XML namespace does not seem to be recognized, as a workaround you could try using the CLR assembly-based XML namespace:


    xmlns:niGraphs="clr-namespace:NationalInstruments.Controls;assembly=NationalInstruments.Controls.Graphs"

    ...

    <DataTemplate DataType="{x:Type niGraphs:Plot}">
        ...

~ Paul H
0 Kudos
Message 10 of 15
(6,159 Views)