Hi,
I am trying to create a simple xamDataChart with Legend box, but legend box is not completely visible.
And here is my XAML code for chart definition.
<ig:XamDataChart Grid.RowSpan="2" HorizontalAlignment="Stretch" Margin="0" Name="theChart" Background="#EBF3FB" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="1"> <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="xmXAxis" ItemsSource="{Binding}" Label="{}{X}" Stroke="Transparent" MajorStroke="Transparent"> <ig:CategoryXAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideBottom" Extent="35" Visibility="Visible" /> </ig:CategoryXAxis.LabelSettings> </ig:CategoryXAxis> <ig:NumericYAxis x:Name="xmYAxisPrice" MajorStroke="Transparent" MinorStroke="Transparent"> <ig:NumericYAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideLeft" Extent="55" Visibility="Visible" /> </ig:NumericYAxis.LabelSettings> </ig:NumericYAxis> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:LineSeries Thickness="2" ItemsSource="{Binding}" Brush="Blue" UnknownValuePlotting="LinearInterpolate" ValueMemberPath="Y1" XAxis="{Binding ElementName=xmXAxis}" YAxis="{Binding ElementName=xmYAxisPrice}" Title="ABC" Legend="{Binding ElementName=MyLegendItem}" /> </ig:XamDataChart.Series> </ig:XamDataChart> <ig:Legend x:Name="MyLegendItem" HorizontalAlignment="Right" VerticalAlignment="Top" Width="200" Height="100" Content="Legend"></ig:Legend>
I don't know what I am doing wrong here. Kindly help.
Hi, could you shart the xaml code for the element that contains these two?
-Graham
Hi Graham,
Thank you for your response. Here is the complete page XAML, I just removed the TreeView Items.
<UserControl x:Class="MyNamespace.IC" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:igChart="http://schemas.infragistics.com/xamWebChart" xmlns:ig="http://schemas.infragistics.com/xaml" xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" mc:Ignorable="d" Loaded="IC_Loaded" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"> <ScrollViewer VerticalScrollBarVisibility="Auto" d:LayoutOverrides="Width, Height" > <Grid x:Name="LayoutRoot" Style="{StaticResource GridMainPageOuter}" MinWidth="600" MinHeight="380"> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.02*"/> <ColumnDefinition Width="440"/> <ColumnDefinition Width="0.02*"/> <ColumnDefinition Width="0.93*"/> <ColumnDefinition Width="0.03*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition Height="8"/> <RowDefinition Height="*"/> <RowDefinition Height="5"/> <RowDefinition Height="120"/> <RowDefinition Height="20"/> </Grid.RowDefinitions>
<Border BorderBrush="Gray" Background="Transparent" x:Name="brdMainText" BorderThickness="0,0,0,4" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" />
<TextBlock x:Name="lblCompany" Style="{StaticResource TextBlockTitle}" Text="Comparison : " Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="3" /> <TextBlock x:Name="lblPublishingHouse" Style="{StaticResource TextBlockPromptTitle}" Text="*report" Grid.Column="3" Grid.Row="0" HorizontalAlignment="Right" FontStyle="Italic" />
<Grid x:Name="gLeft" Style="{StaticResource ExpandGridInformation}" Grid.Column="1" Grid.Row="2" MinHeight="270" Background="#EBF3FB" > <Grid.ColumnDefinitions> <ColumnDefinition Width="0.01*"/>
<ColumnDefinition Width="0.60*"/> <ColumnDefinition Width="0.38*"/>
<ColumnDefinition Width="0.01*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="50"/> <RowDefinition Height="35"/> <RowDefinition Height="15"/> <RowDefinition Height="15"/> <RowDefinition Height="*"/> <RowDefinition/> </Grid.RowDefinitions> <Grid x:Name="grdTopLeft" Style="{StaticResource GridInformation}" Grid.ColumnSpan="4" Grid.Row="0" Grid.Column="0" Height="50" Margin="0" Background="#B0D0FF"> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.01*"/>
<ColumnDefinition Width="0.01*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <TextBlock x:Name="lbPerformance" VerticalAlignment="Top" Text="Categories" Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" TextWrapping="Wrap" d:LayoutOverrides="Width" FontSize="16" FontFamily="Verdana" Foreground="Black"/> <TextBlock x:Name="lbIndicators" HorizontalAlignment="Right" Margin="0" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" Text="Indicators" TextWrapping="Wrap" Foreground="Black"/> <ComboBox x:Name="ddlYear" Margin="0" Grid.Column="2" Grid.Row="1" Width="70" VerticalAlignment="Top" SelectionChanged="ddlYear_SelectionChanged"> </ComboBox> </Grid> <TextBlock x:Name="lbPosChange" Margin="0" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Text="Average within industry:" TextWrapping="Wrap" d:LayoutOverrides="Width" FontWeight="Bold" FontSize="18"/> <TextBlock x:Name="lbPosChangeValue" Margin="0" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Text="80%" TextWrapping="Wrap" d:LayoutOverrides="Width" FontWeight="Bold" FontSize="18" Foreground="#FF0D5EEA"/> <StackPanel FlowDirection="LeftToRight" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="2" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center"> <TextBlock Text=" " /> <TextBlock x:Name="lbValue" Margin="0" Text="Value " TextWrapping="Wrap" FontWeight="Bold" FontSize="10" Foreground="Black"/> <TextBlock x:Name="lbAvg" Margin="0" Text=" Avg. " TextWrapping="Wrap" FontWeight="Bold" FontSize="10" Foreground="Black"/> <TextBlock x:Name="lbSTDev" Margin="0" Text=" St. Dev. " TextWrapping="Wrap" FontWeight="Bold" FontSize="10" Foreground="Black"/> <TextBlock x:Name="lbPct" Margin="0" Text=" Pct " TextWrapping="Wrap" FontWeight="Bold" FontSize="10" Foreground="Black"/> </StackPanel> <Border BorderBrush="Gray" Background="Transparent" x:Name="brdIndustryLine" BorderThickness="0,0,0,2" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Width="185" HorizontalAlignment="Right" VerticalAlignment="Top" /> <ig:XamTree x:Name="webTree" Margin="0" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Height="Auto" SelectionType="Single" VerticalAlignment="Top" Background="{x:Null}" d:LayoutOverrides="Width" BorderThickness="0" ItemExpansionChanged="XamWebTree_ItemExpansionChanged" ActiveItemChanging="webTree_ActiveItemChanging"> <!--Tree Item here --> </ig:XamTree>
</Grid> <Grid x:Name="gChart" Style="{StaticResource ExpandGridInformation}" Grid.Column="3" Grid.Row="2" MinHeight="240" Background="#EBF3FB"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="30" /> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBlock Grid.Column="0" Grid.Row="0" FontFamily="Arial" FontWeight="Bold" FontSize="16" HorizontalAlignment="Left" Name="lblMeasureOnChart" VerticalAlignment="Top" Text=" " /> <ig:XamDataChart Grid.RowSpan="2" HorizontalAlignment="Stretch" Margin="0" Name="theChart" Background="#EBF3FB" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="1"> <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="xmXAxis" ItemsSource="{Binding}" Label="{}{X}" Stroke="Transparent" MajorStroke="Transparent"> <ig:CategoryXAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideBottom" Extent="35" Visibility="Visible" /> </ig:CategoryXAxis.LabelSettings> </ig:CategoryXAxis> <ig:NumericYAxis x:Name="xmYAxisPrice" MajorStroke="Transparent" MinorStroke="Transparent"> <ig:NumericYAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideLeft" Extent="55" Visibility="Visible" /> </ig:NumericYAxis.LabelSettings> </ig:NumericYAxis> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:LineSeries Thickness="2" ItemsSource="{Binding}" Brush="Blue" UnknownValuePlotting="LinearInterpolate" ValueMemberPath="Y1" XAxis="{Binding ElementName=xmXAxis}" YAxis="{Binding ElementName=xmYAxisPrice}" Title="ABC" Legend="{Binding ElementName=MyLegendItem}" /> </ig:XamDataChart.Series> </ig:XamDataChart> <ig:Legend x:Name="MyLegendItem" HorizontalAlignment="Right" VerticalAlignment="Top" Width="200" Height="100" Content="Legend"></ig:Legend> </Grid>
<Grid x:Name="grdTable" Background="#EBF3FB" VerticalAlignment="Top" Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="3" Height="120"> <Grid.RowDefinitions> <RowDefinition Height="18"/> <RowDefinition Height="2"/> <RowDefinition Height="17"/> <RowDefinition Height="17"/> <RowDefinition Height="17"/> <RowDefinition Height="17"/> <RowDefinition Height="17"/> <RowDefinition Height="15"/> </Grid.RowDefinitions> </Grid> <TextBlock x:Name="lblNote" Style="{StaticResource TextBlockPromptTitle}" Foreground="Red" Text="* This view contains calculated data not provided in the source document" Grid.Column="1" Grid.Row="5" Grid.ColumnSpan="3" FontStyle="Italic" /> <controlsToolkit:BusyIndicator x:Name="actPTV" IsBusy="False" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="4" Grid.RowSpan="2" BusyContent="Calculating..." DisplayAfter="00:00:00" Margin="1,-3,-1,-27"/> </Grid> </ScrollViewer></UserControl>
you put the legend in the first row of the grid, yet you are setting the height of the first row to 30. This is what is cutting off most of the legend. Notice the difference if you set the first row of the grid to Height="Auto"? What kind of display where you intending here?
Thank you for your response. Yes If I set grid row Height = "Auto" then legend visible however I am not getting that why Legend is coming in first row (My believe was that it is the part of XamDataCHART so take space in that datachart row). I created first row of Grid because I want to show the title of Chart in TextBlock.
However my exact requirements was to show the Legend below the X-Axis values in XamDataChart .
I tried to set HorizontalAlignment and VerticalAlignment of Legend by these lines but it does not work.
<ig:Legend x:Name="MyLegendItem" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Width="200" Height="100" Content="Legend"></ig:Legend>
I will be very thankful if you help me to solve this problem, you have my complete XAML so you can let me know how can I acheive this within my XAML.
The legend is a seperate control that coordinates with the chart. So you can place it however and wherever you like.If you want to put it below the chart you can just place it in a row underneath the grid, like so.
<Grid x:Name="gChart" Style="{StaticResource ExpandGridInformation}" Grid.Column="3" Grid.Row="2" MinHeight="240" Background="#EBF3FB"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <TextBlock Grid.Column="0" Grid.Row="0" FontFamily="Arial" FontWeight="Bold" FontSize="16" HorizontalAlignment="Left" Name="lblMeasureOnChart" VerticalAlignment="Top" Text=" " /> <ig:XamDataChart Grid.Row="0" HorizontalAlignment="Stretch" Margin="0" Name="theChart" Background="#EBF3FB" VerticalAlignment="Stretch" Grid.Column="0"> <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="xmXAxis" ItemsSource="{Binding}" Label="{}{X}" Stroke="Transparent" MajorStroke="Transparent"> <ig:CategoryXAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideBottom" Extent="35" Visibility="Visible" /> </ig:CategoryXAxis.LabelSettings> </ig:CategoryXAxis> <ig:NumericYAxis x:Name="xmYAxisPrice" MajorStroke="Transparent" MinorStroke="Transparent"> <ig:NumericYAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideLeft" Extent="55" Visibility="Visible" /> </ig:NumericYAxis.LabelSettings> </ig:NumericYAxis> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:LineSeries Thickness="2" ItemsSource="{Binding}" Brush="Blue" UnknownValuePlotting="LinearInterpolate" ValueMemberPath="Y1" XAxis="{Binding ElementName=xmXAxis}" YAxis="{Binding ElementName=xmYAxisPrice}" Title="ABC" Legend="{Binding ElementName=MyLegendItem}" /> </ig:XamDataChart.Series> </ig:XamDataChart> <ig:Legend x:Name="MyLegendItem" HorizontalAlignment="Stretch" VerticalAlignment="Top" Content="Legend" Grid.Row="1"></ig:Legend> </Grid>
Hope this helps!-Graham
You can just change the orientation property of the legend to Horizontal.
Let me know if that helps.
Hello Graham,
Kindly help me to resolve this issue.
Thanks in advance.
Thank you Graham,
It show the Legend below the chart but its showing Series vertically as shown here
But I would like to have it in Horizaontally aligned as shown in previous post so that it take very less space. I will have 3 series in my chart so I am sure it can come in one line.
Kindly help.