Hi,
I’ve set a style for the xamCharts Label, in order to set font properties and angle etc:
<Style TargetType="{x:Type igCA:Label}">
<Setter Property="FontFamily"
Value="Verdana" />
<Setter Property="FontSize"
Value="12" />
<Setter Property="Foreground"
Value="Purple" />
<Setter Property="Angle"
Value="45" />
</Style>
This works fine so far. I then tried adding a trigger to the style:
<Trigger Property="Label.IsMouseOver"
Value="True">
Value="Red" />
</Trigger>
I also tried registering the Labels MouseDown event:
EventManager.RegisterClassHandler(GetType(Label), Label.MouseDownEvent, _
New MouseButtonEventHandler(AddressOf Label_MouseDown))
Neither of which work; the foreground of the label doesn’t change when the mouse is over it and the event never gets raised.
Upon investigation, it appears that despite Label inheriting from ChartFrameworkContentElement (that includes the IsMouseOver property and MouseDown event), these objects never get added to the visual tree of the chart. It looks like these Label objects are used to just store font properties that are then used to draw text on an AxisLabelsPane (canvas)?
For dual-series charts, I’ve added the ability for the end user to click on a data point in order to filter a grid of data below by the data-points year and category (in one case). They can also click on a legend item to filter the grid by just the selected category. The only thing missing is allowing them to click one of the x-axis (year) labels to filter the grid by all items within the selected year.
Are there any plans to include this functionality in the future? Should I raise a feature request? Or can anyone think of a solution that would achieve this in the current version!?
Regards,
Dave
p.s. I mentioned above that users could click legend items to apply filters.... I lied.... I hadn't done this at the time of posting (but thought it'd be simple). LegendItem doesn't even expose any events!!! and doing a HitTest on the Chart's MouseUp doesn't find the legened item like it does with DataPoint.... help!
Dave,
Unfortunately the Text for the axis labels on this chart is rendered directly to a DrawingContext so its not very possible to make them interactive, currently. You could submit a feature request in this regard however. As for the legend labels, these do get added to the visual tree, so you can modify them to whatever end:
Markup:
<Window x:Class="WpfApplication20.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:igChart="http://infragistics.com/Chart">
<Window.Resources>
<Style x:Key="labelStyle" TargetType="TextBlock">
<Style.Triggers>
</Style.Triggers>
</Window.Resources>
<Grid>
<igChart:XamChart x:Name="theChart" MouseEnter="theChart_MouseEnter">
</igChart:XamChart>
</Grid>
</Window>
Code:
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
InitializeComponent();
}
private void theChart_MouseEnter(object sender, MouseEventArgs e)
foreach (TextBlock tb in VisualEnumerator<TextBlock>.Enumerate(theChart, "Legend"))
tb.Style = (Style)Resources["labelStyle"];
tb.MouseUp += new MouseButtonEventHandler(tb_MouseUp);
void tb_MouseUp(object sender, MouseButtonEventArgs e)
MessageBox.Show(((TextBlock)sender).Text);
public class VisualEnumerator<T> where T : DependencyObject
private static IEnumerable<T> EnumerateHelper(DependencyObject currentRoot, string under, bool isUnder)
int count = VisualTreeHelper.GetChildrenCount(currentRoot);
if (!isUnder)
isUnder = currentRoot.GetType().Name == under;
for (int i = 0; i < count; i++)
DependencyObject control = VisualTreeHelper.GetChild(currentRoot, i);
if (control is T && isUnder)
yield return (T)control;
int subCount = VisualTreeHelper.GetChildrenCount(control);
if (subCount > 0)
foreach (T subControl in EnumerateHelper(control, under, isUnder))
yield return subControl;
public static IEnumerable<T> Enumerate(DependencyObject root, string under)
bool isUnder = root.GetType().Name == under;
foreach (T control in EnumerateHelper(root, under, isUnder))
yield return control;
-Graham
I am using XamDataChart and try to catch the MouseDown event on Axis without success.
I am working on a task to allow user interactively change the range of the chart, the idea is allow them to click on the label of the axis to modify the range. I have temporary textboxes did the job, but it will be great to allow chaning on the label.
Is there way to do it?
Thanks.
Solved. :)