Back to Devexpress

HeatmapControl.CalcHitInfo(Point) Method

wpf-devexpress-dot-xpf-dot-charts-dot-heatmap-dot-heatmapcontrol-dot-calchitinfo-x28-system-dot-windows-dot-point-x29.md

latest10.0 KB
Original Source

HeatmapControl.CalcHitInfo(Point) Method

Returns information about the visual element under the specified hit point.

Namespace : DevExpress.Xpf.Charts.Heatmap

Assembly : DevExpress.Xpf.Charts.v25.2.dll

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public HeatmapHitInfo CalcHitInfo(
    Point point
)
vb
Public Function CalcHitInfo(
    point As Point
) As HeatmapHitInfo

Parameters

NameTypeDescription
pointPoint

Specifies the hit point relative to the control’s upper-left corner.

|

Returns

TypeDescription
HeatmapHitInfo

Contains information about the visual element under the specified hit point.

|

Remarks

The following example shows how to determine what a heatmap element is in a test point and how to collect information related to this element.

Call the HeatmapControl.CalcHitInfo method to obtain information about a specific point within the Heatmap Control. This method returns a HeatmapHitInfo object that contains information related to heatmap elements positioned in the test point.

xaml
<Window xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"  
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
        xmlns:dxh="http://schemas.devexpress.com/winfx/2008/xaml/heatmap"
        x:Class="HeatmapChart.MainWindow"
        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:local="clr-namespace:HeatmapChart" 
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        mc:Ignorable="d"
        dx:ThemeManager.ThemeName="Office2019Colorful"
        Title="MainWindow" Height="410" Width="728">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="130"/>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <dxe:TextEdit Grid.Column="0" x:Name="textEdit" TextWrapping="Wrap" 
                      VerticalContentAlignment="Top" BorderBrush="Transparent"/>
        <dxh:HeatmapControl x:Name="heatmapControl" 
                            Grid.Column="1"
                            ToolTipEnabled="True" Margin="10" 
                            MouseMove="heatmapControl_MouseMove">
            <dxh:HeatmapControl.DataContext>
                <local:MatrixHeatmapViewModel />
            </dxh:HeatmapControl.DataContext>
            <dxh:HeatmapControl.DataAdapter>
                <dxh:HeatmapMatrixAdapter XArguments="{Binding XArguments}" 
                                          YArguments="{Binding YArguments}" 
                                          Values="{Binding Values}" />
            </dxh:HeatmapControl.DataAdapter>
            <dxh:HeatmapControl.ColorProvider>
                <!--...-->
            </dxh:HeatmapControl.ColorProvider>
            <dxh:HeatmapControl.Legend>
                <dxh:HeatmapLegend Margin="0, 0, 4, 10" Visible="True">
                    <dxh:HeatmapLegend.Title>
                        <dxc:LegendTitle Content="Revenue" />
                    </dxh:HeatmapLegend.Title>
                </dxh:HeatmapLegend>
            </dxh:HeatmapControl.Legend>
            <dxh:HeatmapControl.AxisX>
                <dxh:HeatmapAxis x:Name="xAxis" Reverse="True" Alignment="Near" 
                                 AutoGrid="False" GridSpacing="1">
                    <dxh:HeatmapAxis.Title>
                        <dxc:AxisTitle Content="Region" Visibility="Visible"/>
                    </dxh:HeatmapAxis.Title>
                    <dxh:HeatmapAxis.Label>
                        <dxc:AxisLabel x:Name="xAxisLabel"/>
                    </dxh:HeatmapAxis.Label>
                </dxh:HeatmapAxis>
            </dxh:HeatmapControl.AxisX>
            <dxh:HeatmapControl.AxisY>
                <dxh:HeatmapAxis x:Name="yAxis" Reverse="True" Alignment="Near">
                    <dxh:HeatmapAxis.Title>
                        <dxc:AxisTitle Content="Product Category" Visibility="Visible"/>
                    </dxh:HeatmapAxis.Title>
                    <dxh:HeatmapAxis.Label>
                        <dxc:AxisLabel x:Name="yAxisLabel"/>
                    </dxh:HeatmapAxis.Label>
                </dxh:HeatmapAxis>
            </dxh:HeatmapControl.AxisY>
            <dxh:HeatmapControl.Label>
                <dxh:HeatmapLabel Foreground="Black" 
                                  Background="#70ffffff" 
                                  Padding="2" 
                                  TextOrientation="Horizontal"
                                  TextPattern="${V}M"/>
            </dxh:HeatmapControl.Label>
        </dxh:HeatmapControl>
    </Grid>
</Window>
csharp
using DevExpress.Xpf.Charts;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Input;

namespace HeatmapChart {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }

        private void heatmapControl_MouseMove(object sender, MouseEventArgs e) {
            // Obtain hit information under the test point.
            HeatmapHitInfo hitInfo = heatmapControl.CalcHitInfo(e.GetPosition(heatmapControl));
            StringBuilder builder = new StringBuilder();

            if (hitInfo.InAxis) builder.AppendLine($"In axis:");
            if (hitInfo.AxisLabel != null)
                builder.AppendLine($"Label: {hitInfo.AxisLabel.Name}");
            if (hitInfo.AxisTitle != null)
                builder.AppendLine($"Axis title: {hitInfo.AxisTitle.Content}");
            if (hitInfo.InHeatmapCell)
                builder.AppendLine($"In cell:{Environment.NewLine}X ({hitInfo.HeatmapCell.XArgument}),{Environment.NewLine}Y ({hitInfo.HeatmapCell.YArgument})");
            if (hitInfo.InLegend)
                builder.AppendLine($"In legend");

            // Show hit-testing results.
            if (builder.Length > 0)
                textEdit.Text = string.Format($"Hit-testing results:{Environment.NewLine}{builder}");
            else
                textEdit.Text = "Move the mouse pointer over the heatmap to see information on hovered heatmap elements.";
        }
    }
    public class MatrixHeatmapViewModel {
        public string[] XArguments { get; set; }
        public string[] YArguments { get; set; }
        public double[,] Values { get; set; }
        public MatrixHeatmapViewModel() {
            XArguments = new string[] { "North", "South", "West", "East", "Central" };
            YArguments = new string[] { "Accessories", "Bikes", "Clothing", "Components" };
            Values = new double[,] {
               { 214.3, 530.1, 630.2, 854.4, 313.4 },
               { 321.3, 514.4, 281.3, 533.4, 541.9 },
               { 604.3, 429.1, 632.6, 438.4, 265.4 },
               { 485.3, 544.7, 740.3, 661.4, 516.6 }
            };
        }
    }
}
vb
Imports DevExpress.Xpf.Charts
Imports System
Imports System.Text

Namespace HeatmapChart
    Public Partial Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub heatmapControl_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
            ' Obtain hit information under the test point.
            Dim hitInfo As HeatmapHitInfo = heatmapControl.CalcHitInfo(e.GetPosition(heatmapControl))
            Dim builder As StringBuilder = New StringBuilder()
            If hitInfo.InAxis Then builder.AppendLine($"In axis:")
            If hitInfo.AxisLabel IsNot Nothing Then builder.AppendLine($"Label: {hitInfo.AxisLabel.Name}")
            If hitInfo.AxisTitle IsNot Nothing Then builder.AppendLine($"Axis title: {hitInfo.AxisTitle.Content}")
            If hitInfo.InHeatmapCell Then builder.AppendLine($"In cell:{Environment.NewLine}X ({hitInfo.HeatmapCell.XArgument}),{Environment.NewLine}Y ({hitInfo.HeatmapCell.YArgument})")
            If hitInfo.InLegend Then builder.AppendLine($"In legend")

            ' Show hit-testing results.
            If builder.Length > 0 Then
                textEdit.Text = String.Format($"Hit-testing results:{Environment.NewLine}{builder}")
            Else
                textEdit.Text = "Move the mouse pointer over the heatmap to see information on hovered heatmap elements."
            End If
        End Sub
    End Class

    Public Class MatrixHeatmapViewModel
        Public Property XArguments As String()
        Public Property YArguments As String()
        Public Property Values As Double(,)

        Public Sub New()
            XArguments = New String() {"North", "South", "West", "East", "Central"}
            YArguments = New String() {"Accessories", "Bikes", "Clothing", "Components"}
            Values = New Double(,) {
            {214.3, 530.1, 630.2, 854.4, 313.4},
            {321.3, 514.4, 281.3, 533.4, 541.9},
            {604.3, 429.1, 632.6, 438.4, 265.4},
            {485.3, 544.7, 740.3, 661.4, 516.6}}
        End Sub
    End Class
End Namespace

See Also

HeatmapControl Class

HeatmapControl Members

DevExpress.Xpf.Charts.Heatmap Namespace