Hi,
I want to get series name and value on the clicked element in the column graph.
For it I handle MouseDown event and call HitTest function. But it returns null reference in his SelectedObject property
It only works properly in the 3d Mode .
What is wrong?
The SelectedObject property from HitTestArgs is null if mouse is not above a DataPoint (Series). Only when data points are selected the SelectedObject will return a reference to a data point. This example shows how selection works:
C#:
using System;using System.IO;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Navigation;using Infragistics.Windows.Chart;
namespace UntitledProject8{ public partial class Window1 { public Window1() { this.InitializeComponent(); // Insert code required on object creation below this point. }
protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e) { HitTestArgs args = this.Chart1.HitTest(e); base.OnMouseDown(e); } }}
XAML:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igCA="http://infragistics.com/Chart" x:Class="UntitledProject8.Window1" x:Name="Window" Title="Window1" Width="640" Height="480">
<Grid x:Name="LayoutRoot"> <igCA:XamChart Name="Chart1" Margin="8,8,8,8"> <igCA:XamChart.Series> <igCA:Series> <igCA:Series.DataPoints> <igCA:DataPoint Value="2"/> <igCA:DataPoint Value="8"/> <igCA:DataPoint Value="6"/> <igCA:DataPoint Value="7"/> </igCA:Series.DataPoints> </igCA:Series> </igCA:XamChart.Series> </igCA:XamChart> </Grid></Window>
as per above, I cannot get the hittest to return a selected object or pointindex >0 for a 2D chart
The hittest works fine on 3D Charts, but when clicking directly on a 2D datapoint, the selectedobject in hittestargs is always null.
I would assume because the samples only have a 3D selection example, then its a known issue for 2D Charts.
Is this a known issue and is there any workaround ?
SelectedObject returns a DataPoint for me in a simple 2D column chart. what type of chart/datapoint are you clicking on?
Yeah I have seen issues with it in scatterline. Add like 30-40 points. I'd say 80% of my points work, but the other 20 don't, no matter what I do. I am not sure if this is a wpf issue or chart control issue. I even changed my code to use Marker Templates with button click, and for some reason some points refuse to get click/mouse over events. Very strange. And my buttons points are fairly large. As big as the mouse pointer.
i tested this out and i was able to get a value for SelectedObject consistently with a ScatterLine chart with 30 points. here is the sample code i used -- please let me know if this works on your machine -- if so, how should i modify this code to reproduce the problem?
private void XamChart_MouseDown(object sender, MouseButtonEventArgs e) { base.OnMouseDown(e); HitTestArgs args = this.XamChart1.HitTest(e); DataPoint selectedPoint = args.SelectedObject as DataPoint; if (selectedPoint != null) { Console.WriteLine("Clicked " + selectedPoint.ChartParameters[0].Value + ", " + selectedPoint.ChartParameters[1].Value); } }
<Window x:Class="WpfApplication37.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igCA="clr-namespace:Infragistics.Windows.Chart;assembly=Infragistics3.Wpf.Chart.v7.2" Title="Window1" Height="300" Width="300"> <igCA:XamChart x:Name="XamChart1" MouseDown="XamChart_MouseDown"> <igCA:XamChart.Series> <igCA:Series ChartType="ScatterLine"> <igCA:Series.Marker> <igCA:Marker /> </igCA:Series.Marker> <igCA:Series.DataPoints> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="1" /> <igCA:ChartParameter Type="ValueY" Value="1" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="2" /> <igCA:ChartParameter Type="ValueY" Value="2" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="3" /> <igCA:ChartParameter Type="ValueY" Value="3" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="4" /> <igCA:ChartParameter Type="ValueY" Value="4" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="5" /> <igCA:ChartParameter Type="ValueY" Value="5" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="6" /> <igCA:ChartParameter Type="ValueY" Value="6" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="7" /> <igCA:ChartParameter Type="ValueY" Value="7" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="8" /> <igCA:ChartParameter Type="ValueY" Value="8" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="9" /> <igCA:ChartParameter Type="ValueY" Value="9" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="10" /> <igCA:ChartParameter Type="ValueY" Value="10" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="11" /> <igCA:ChartParameter Type="ValueY" Value="11" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="12" /> <igCA:ChartParameter Type="ValueY" Value="12" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="13" /> <igCA:ChartParameter Type="ValueY" Value="13" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="14" /> <igCA:ChartParameter Type="ValueY" Value="14" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="15" /> <igCA:ChartParameter Type="ValueY" Value="15" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="16" /> <igCA:ChartParameter Type="ValueY" Value="16" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="17" /> <igCA:ChartParameter Type="ValueY" Value="17" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="18" /> <igCA:ChartParameter Type="ValueY" Value="18" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="19" /> <igCA:ChartParameter Type="ValueY" Value="19" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="20" /> <igCA:ChartParameter Type="ValueY" Value="20" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="21" /> <igCA:ChartParameter Type="ValueY" Value="21" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="22" /> <igCA:ChartParameter Type="ValueY" Value="22" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="23" /> <igCA:ChartParameter Type="ValueY" Value="23" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="24" /> <igCA:ChartParameter Type="ValueY" Value="24" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="25" /> <igCA:ChartParameter Type="ValueY" Value="25" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="26" /> <igCA:ChartParameter Type="ValueY" Value="26" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="27" /> <igCA:ChartParameter Type="ValueY" Value="27" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="28" /> <igCA:ChartParameter Type="ValueY" Value="28" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="29" /> <igCA:ChartParameter Type="ValueY" Value="29" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> <igCA:DataPoint> <igCA:DataPoint.ChartParameters> <igCA:ChartParameter Type="ValueX" Value="30" /> <igCA:ChartParameter Type="ValueY" Value="30" /> </igCA:DataPoint.ChartParameters> </igCA:DataPoint> </igCA:Series.DataPoints> </igCA:Series> </igCA:XamChart.Series> </igCA:XamChart></Window>
Well yours works fine for me. Wierd. I'm on vaca next week but when I get back I will try to figure out what I am doing different. I guess one of the main things I do different is dynamically add and remove data points. And I have more series. When I figure it out will post.
Update: Just got another clue. Using snoop I can see that Mouse Enter Events are being block by a TextBlock on some data points. I set the Marker Foreground color to transparent becuase I don't want labels on my data points, but somehow these invisible TextBlocks are blocking the data points from getting a mouse over.
How do we get rid of the Text Labels on Markers?
Format? or LabelDistance?
i saw this submitted as a bug (BR35669) and fixed it today. your issue should be resolved in an upcoming hotfix. you should be able to work around the problem by setting UseDataTemplate = false on your series objects.
why doesn't HitTest() behave the same in 2D as it does in 3D? If I have a stacked bar or stacked column chart, I should be able to HitTest() a click over a column or bar in 2D or 3D and get the same behavior. Yet it doesn't.
I am attaching a simple example. You will need to re-add references to your chart dll's to build the application. the application displays a simple stacked column chart that handles double clicks with a HitTest() call. You can switch between 2D and 3D using a dropdown menu. Without using Markers in the 2D chart, how can I get HitTest to return the same object when performed in 2D or 3D?
using the DataPointTemplate class should suffice. and about removing marker labels, i guess setting the format to " " is your best option.
But I need the marker to use the data template with a scatter line chart's data points... don't I? Or can I use a data point template with a scatter line chart. The documentation is a little confusing on the subject of data templates with scatter line charts. I need a data template because my points are buttons.
From About DataPointTemplates
You can target the following DataTypes in your DataTemplates:
There is nothing there about scatterline.
removing the Marker from the Series might be a better solution...