Hi,
I'm using a xamDataChart into a tile manager to display datas.
Every new data dropped into the tile manager generate a xamdatachart programmatically, every thing is ok, but I can't add a legend to the Chart.
The legend is ok, I can add it into a tile, but not in a XamDataChart...
I'm missong something, but can't figure out what :
Here is may code :
XamDataChart AcquisDataChart = new XamDataChart(); AcquisDataChart.WindowPositionHorizontal = 0; AcquisDataChart.WindowPositionVertical = 0; AcquisDataChart.WindowScaleHorizontal = 0.05; AcquisDataChart.WindowScaleVertical = 1; AcquisDataChart.HorizontalZoomable = true; AcquisDataChart.HorizontalZoombarVisibility = Visibility.Visible; AcquisDataChart.VerticalZoomable = true; AcquisDataChart.VerticalZoombarVisibility = Visibility.Visible; AcquisDataChart.UseTiledZooming = true; AcquisDataChart.AllowDrop = true; AcquisDataChart.Drop += AcquisDataChart_DropSerie; AcquisDataChart.VerticalAlignment = VerticalAlignment.Stretch; AcquisDataChart.Margin = new Thickness(0, 0, 0, 0); AcquisDataChart.Padding = new Thickness(0, 0, 0, 0); legend = new Legend { Content = "Legend", Margin = new Thickness(20), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Right }; TileManager.Items.Add(AcquisDataChart);
//On crée les axes et on binde au nouveau jeu de données. CategoryDateTimeXAxis catXAxis = new CategoryDateTimeXAxis(); catXAxis.ItemsSource = newData.listOfDatas; catXAxis.DateTimeMemberPath = "Time"; catXAxis.LabelSettings = new AxisLabelSettings(); catXAxis.LabelSettings.Extent = 30; catXAxis.LabelSettings.Location = AxisLabelsLocation.OutsideBottom; catXAxis.Label = "{Time:HH:mm:ss}"; NumericYAxis numYAxis = new NumericYAxis(); numYAxis.LabelSettings = new AxisLabelSettings(); numYAxis.LabelSettings.Extent = 30; LineSeries line = new LineSeries(); line.Name = data.ToString(); line.ValueMemberPath = "Y"; line.ItemsSource = newData.listOfDatas; line.XAxis = catXAxis; line.YAxis = numYAxis; line.MarkerType = MarkerType.None; line.Thickness = 1; line.Resolution = 1.5; line.IsHighlightingEnabled = true; line.IsTransitionInEnabled = true; line.IsCustomCategoryStyleAllowed = true; line.MouseLeftButtonDown += Line_MouseLeftButtonDown; line.MouseLeftButtonUp += Line_MouseLeftButtonUp; line.MouseMove += Line_MouseMove; line.Title = newData.Name + "-" + newData.AcquiSource + "-" + newData.LapSource; line.Legend = legend; legend.Visibility = Visibility.Visible; AcquisDataChart.Axes.Add(catXAxis); AcquisDataChart.Axes.Add(numYAxis); AcquisDataChart.Series.Add(line);
Thank you for your help !
Hello,
Thank you for contacting Infragistics. The legend doesn't appear to be within any element on screen or added to your tile manager in your code. In order to take full advantage of where the legend is displayed in relationship to the DataChart I recommend using a XamDock.
An example of this can be found online at: Legend Docking
https://www.infragistics.com/samples/wpf/data-chart/legend-docking
Otherwise you will need to specify a container to incorporate both the chart and legend. Then place the container in the tile.
eg.
<Grid x:Name="GridWithItemLegend"> <ig:XamDataChart > <ig:XamDataChart.Axes> ... </ig:XamDataChart.Axes> <ig:XamDataChart.Series> ... </ig:XamDataChart.Series> </ig:XamDataChart> <!--#BEGIN SNIPPET#--> <!-- ========================================================================== --> <ig:ItemLegend x:Name="ItemLegend" Content="{Binding XWDC_LegendTypes_ItemLegend, Source={StaticResource Strings}}" Margin="20,20,10,20" VerticalAlignment="Top" HorizontalAlignment="Right"> </ig:ItemLegend> <!-- ========================================================================== --> <!--#END SNIPPET#--> </Grid>
Let me know if you have any questions.
Legend is displayed ! I added this to my code behind :
XamDock dock = new XamDock(); dock.Children.Add(AcquisDataChart); dock.Children.Add(legend); TileManager.Items.Add(dock);
Hello Alex,
Thank you for following up. I am glad you were able to resolve this on your own. Yes, this is the correct approach I would have taken as well. Let me know if you have any additional questions.