Back to Devexpress

HeatmapDataSourceAdapter.XArgumentDataMember Property

corelibraries-devexpress-dot-xtracharts-dot-heatmap-dot-heatmapdatasourceadapter-4badf300.md

latest14.0 KB
Original Source

HeatmapDataSourceAdapter.XArgumentDataMember Property

Gets or sets the name of a data source member that stores x-axis arguments.

Namespace : DevExpress.XtraCharts.Heatmap

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public string XArgumentDataMember { get; set; }
vb
Public Property XArgumentDataMember As String

Property Value

TypeDescription
String

The data source member name.

|

Remarks

You can use objects of any type to specify x-arguments. The HeatmapControl converts the objects to string values and sorts them in alphabetical order.

To show arguments in descending alphabetical order, set the Reverse property of the x-axis to true.

You can implement a comparer to place x-arguments in a specific order. To do this, create a class that implements the IComparer interface and assign an instance of this class to the XArgumentComparer property.

Example

The following example shows how to create a heatmap and bind it to a data source. In this example, the heatmap obtains data from an XML file.

Follow the steps below to create a heatmap:

csharp
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Heatmap;
using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace HeatmapChart {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {
            HeatmapControl heatmap = new HeatmapControl();
            heatmap.Dock = DockStyle.Fill;
            this.Controls.Add(heatmap);

            Palette palette = new Palette("Custom") {
                Color.Red,
                Color.White,
                Color.Green
            };

            HeatmapRangeColorProvider colorProvider = new HeatmapRangeColorProvider() {
                Palette = palette,
                ApproximateColors = true
            };

            colorProvider.RangeStops.Add(new HeatmapRangeStop(0, HeatmapRangeStopType.Percentage));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(-10, HeatmapRangeStopType.Absolute));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(-2.5, HeatmapRangeStopType.Absolute));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(0, HeatmapRangeStopType.Absolute));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(2.5, HeatmapRangeStopType.Absolute));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(10, HeatmapRangeStopType.Absolute));
            colorProvider.RangeStops.Add(new HeatmapRangeStop(1, HeatmapRangeStopType.Percentage));

            heatmap.ColorProvider = colorProvider;

            DataTable data = CreateDataSet("BalanceOfTrade.xml");

            heatmap.DataAdapter = new HeatmapDataSourceAdapter() {
                XArgumentDataMember = "Country",
                YArgumentDataMember = "Product",
                ColorDataMember = "Value",
                DataSource = data                
            };

            heatmap.Titles.Add(new HeatmapTitle { Text = "Balance of Trade" });

            heatmap.Label.Visible = true;
            heatmap.Label.Font = new Font("SegoeUI", 6);
            heatmap.Label.Pattern = "{V}";

            heatmap.ToolTipEnabled = true;
            heatmap.ToolTipController = new DevExpress.Utils.ToolTipController {
                AllowHtmlText = true,
                ToolTipLocation = DevExpress.Utils.ToolTipLocation.RightTop,
                ShowBeak = true
            };
            heatmap.ToolTipTextPattern = "X: <b>{X}</b>\nY: <b>{Y}</b>";
        }
        public static DataTable CreateDataSet(string xmlFileName) {
            string filePath = GetRelativePath(xmlFileName);
            if (!string.IsNullOrWhiteSpace(filePath)) {
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(filePath);
                if (dataSet.Tables.Count > 0)
                    return dataSet.Tables[0];
            }
            return null;
        }
        public static string GetRelativePath(string name) {
            name = "Data\\" + name;
            DirectoryInfo dir = new DirectoryInfo(Application.StartupPath);
            for (int i = 0; i <= 10; i++) {
                string filePath = Path.Combine(dir.FullName, name);
                if (File.Exists(filePath))
                    return filePath;
                dir = Directory.GetParent(dir.FullName);
            }
            return string.Empty;
        }
    }
}
vb
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Heatmap
Imports System
Imports System.Data
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms

Namespace HeatmapChart
    Public Partial Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim heatmap As HeatmapControl = New HeatmapControl()
            heatmap.Dock = DockStyle.Fill
            Me.Controls.Add(heatmap)

            Dim palette As Palette = New Palette("Custom") From {
                System.Drawing.Color.Red,
                System.Drawing.Color.White,
                System.Drawing.Color.Green
            }
            Dim colorProvider As HeatmapRangeColorProvider = New HeatmapRangeColorProvider() With {
                .Palette = palette,
                .ApproximateColors = True
            }
            colorProvider.RangeStops.Add(New HeatmapRangeStop(0, HeatmapRangeStopType.Percentage))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(-10, HeatmapRangeStopType.Absolute))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(-2.5, HeatmapRangeStopType.Absolute))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(0, HeatmapRangeStopType.Absolute))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(2.5, HeatmapRangeStopType.Absolute))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(10, HeatmapRangeStopType.Absolute))
            colorProvider.RangeStops.Add(New HeatmapRangeStop(1, HeatmapRangeStopType.Percentage))
            heatmap.ColorProvider = colorProvider
            Dim data As System.Data.DataTable = HeatmapChart.Form1.CreateDataSet("BalanceOfTrade.xml")
            heatmap.DataAdapter = New HeatmapDataSourceAdapter() With {
                .XArgumentDataMember = "Country",
                .YArgumentDataMember = "Product",
                .ColorDataMember = "Value",
                .DataSource = data                
            }
            heatmap.Titles.Add(New HeatmapTitle With {
                .Text = "Balance of Trade"
            })
            heatmap.Label.Visible = True
            heatmap.Label.Font = New Font("SegoeUI", 6)
            heatmap.Label.Pattern = "{V}"
            heatmap.ToolTipEnabled = True
            heatmap.ToolTipController = New DevExpress.Utils.ToolTipController With {
                .AllowHtmlText = True,
                .ToolTipLocation = DevExpress.Utils.ToolTipLocation.RightTop,
                .ShowBeak = True
            }
            heatmap.ToolTipTextPattern = "X: <b>{X}</b>" & Global.Microsoft.VisualBasic.Constants.vbLf & "Y: <b>{Y}</b>"
        End Sub

        Public Shared Function CreateDataSet(ByVal xmlFileName As String) As System.Data.DataTable
            Dim filePath As String = HeatmapChart.Form1.GetRelativePath(xmlFileName)

            If Not String.IsNullOrWhiteSpace(filePath) Then
                Dim dataSet As System.Data.DataSet = New System.Data.DataSet()
                dataSet.ReadXml(filePath)
                If dataSet.Tables.Count > 0 Then Return dataSet.Tables(0)
            End If

            Return Nothing
        End Function

        Public Shared Function GetRelativePath(ByVal name As String) As String
            name = "Data\" & name
            Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Application.StartupPath)

            For i As Integer = 0 To 10
                Dim filePath As String = System.IO.Path.Combine(dir.FullName, name)
                If System.IO.File.Exists(filePath) Then Return filePath
                dir = System.IO.Directory.GetParent(dir.FullName)
            Next

            Return String.Empty
        End Function
    End Class
End Namespace

The XML file structure looks as follows:

Show XML

xml
<?xml version="1.0" standalone="yes"?>
<BalanceOfTrade xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Item">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="Country" type="xs:string"/>
          <xs:element name="Product" type="xs:string"/>
          <xs:element name="Value" type="xs:double"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <Item>
    <Country>China</Country>
    <Product>Computer</Product>
    <Value>-151.9</Value>
  </Item>
  <Item>
    <Country>China</Country>
    <Product>Oil, Gas, Minerals</Product>
    <Value>1.9</Value>
  </Item>
  <Item>
    <Country>China</Country>
    <Product>Transportation</Product>
    <Value>10.9</Value>
  </Item>
  <Item>
    <Country>China</Country>
    <Product>Apparel</Product>
    <Value>-56.3</Value>
  </Item>
  <!--...-->
</BalanceOfTrade>

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the XArgumentDataMember property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-dashboard-custom-items-extension/CS/CustomItemExtension/CustomItems/Heatmap/HeatmapItemControlProvider.cs#L55

csharp
heatmap.DataAdapter = null;
    dataAdapter.DataSource = dataAdapter.ColorDataMember = dataAdapter.XArgumentDataMember = dataAdapter.YArgumentDataMember = null;
}

winforms-dashboard-custom-items-extension/VB/CustomItemExtension/CustomItems/Heatmap/HeatmapItemControlProvider.vb#L64

vb
dataAdapter.YArgumentDataMember = Nothing
dataAdapter.XArgumentDataMember = dataAdapter.YArgumentDataMember
dataAdapter.ColorDataMember = dataAdapter.XArgumentDataMember

See Also

YArgumentDataMember

HeatmapDataSourceAdapter Class

HeatmapDataSourceAdapter Members

DevExpress.XtraCharts.Heatmap Namespace