Windows演示基础的相关热图

时间:2011-05-31 14:43:23

标签: wpf visualization data-visualization heatmap

有谁知道为WPF绘制相关热图的好工具?

基于评论的示例:

enter image description here

原始图片source

5 个答案:

答案 0 :(得分:7)

免费的WPF工具包有一个TreeMap。您可以在XAML中按如下方式定义它:

<vis:TreeMap ItemsSource="{Binding Path=HeatMap.Sectors}"
              Interpolators="{StaticResource colourInterpolator}">
  <vis:TreeMap.ItemDefinition>
    <vis:TreeMapItemDefinition ValueBinding="{Binding MarketCap}">
      <DataTemplate>
        <Grid>
          <Border x:Name="Border"
                  BorderBrush="Black"
                  BorderThickness="1"
                  Margin="1"
                  Opacity="0.5">                      
          </Border>
          <TextBlock Text="{Binding Name}"
                     TextWrapping="Wrap"
                     FontSize="20"
                     Margin="5"
                     VerticalAlignment="Center"
                     HorizontalAlignment="Center"/>
        </Grid>
      </DataTemplate>
    </vis:TreeMapItemDefinition>
  </vis:TreeMap.ItemDefinition>
</vis:TreeMap>

上面的XAML是我编写的应用程序的片段,显示了财务HeatMaps。您可以在此处看到运行的Silverlight版本:

http://www.scottlogic.co.uk/blog/colin/xaml-finance/

(只需点击'热图'按钮)

答案 1 :(得分:2)

如果您正在寻找商业产品,我建议您查看Telerik控件。 Telerik拥有出色的WPF控件。长列表中包含热图控件。以下是他们列出热图功能的网站的链接:

http://www.telerik.com/products/wpf/map.aspx

如果您正在寻找构建内容,请参阅以下几篇博客文章,介绍如何进行构建(提供源代码):

http://www.garrettgirod.com/?p=111

http://www.nickdarnell.com/?p=833

答案 2 :(得分:2)

Syncfusion charting component似乎提供了热图。

答案 3 :(得分:1)

不是免费组件,但如果您可以使用Telerik库,则可以使用以下内容:

http://www.telerik.com/products/wpf/heatmap.aspx

我过去不得不在一些项目中使用它而且效果很好。

答案 4 :(得分:1)

我使用DevExpress自定义ColorFormatter行为。我无法在市场上找到开箱即用的任何东西。这花了我几天的时间来发展。我的代码在下面得到了解,希望这可以帮助那些人。

编辑:我使用了POCO视图模型和MVVM,但如果您愿意,可以将其更改为不使用POCO。

Example

Table2DViewModel.cs

namespace Interfaces
    {
        public interface ITable2DView
        {
            void SetColorFormatter(float minValue, float maxValue, ColorScaleFormat colorScaleFormat);
        }
    }

ITable2DView.cs

namespace View
{
    public partial class Table2DView : ITable2DView
    {
        public Table2DView()
        {
            InitializeComponent();
        }

        static ColorScaleFormat defaultColorScaleFormat = new ColorScaleFormat
        {
            ColorMin = (Color)ColorConverter.ConvertFromString("#FFF8696B"),
            ColorMiddle = (Color)ColorConverter.ConvertFromString("#FFFFEB84"),
            ColorMax = (Color)ColorConverter.ConvertFromString("#FF63BE7B")
        };

        public void SetColorFormatter(float minValue, float maxValue, ColorScaleFormat colorScaleFormat = null)
        {
            if (colorScaleFormat == null) colorScaleFormat = defaultColorScaleFormat;
            ConditionBehavior.MinValue = minValue;
            ConditionBehavior.MaxValue = maxValue;
            ConditionBehavior.ColorScaleFormat = colorScaleFormat;
        }
    }
}

Table2DView.xaml.cs

namespace Behaviors
{
    public class DynamicConditionBehavior : Behavior<GridControl>
    {
        GridControl Grid => AssociatedObject;

        protected override void OnAttached()
        {
            base.OnAttached();
            Grid.ItemsSourceChanged += OnItemsSourceChanged;
        }

        protected override void OnDetaching()
        {
            Grid.ItemsSourceChanged -= OnItemsSourceChanged;
            base.OnDetaching();
        }

        public ColorScaleFormat ColorScaleFormat { get; set;}
        public float MinValue { get; set; }
        public float MaxValue { get; set; }

        private void OnItemsSourceChanged(object sender, EventArgs e)
        {
            var view = Grid.View as TableView;

            if (view == null) return;

            view.FormatConditions.Clear();

            foreach (var col in Grid.Columns)
            {
                view.FormatConditions.Add(new ColorScaleFormatCondition
                {
                    MinValue = MinValue,
                    MaxValue = MaxValue,
                    FieldName = col.FieldName,
                    Format = ColorScaleFormat,
                });
            }

        }
    }
}

DynamicConditionBehavior.cs

<UserControl x:Class="View"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" 
             xmlns:ViewModels="clr-namespace:ViewModel"
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:behaviors="clr-namespace:Behaviors"
             xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking"
             DataContext="{dxmvvm:ViewModelSource Type={x:Type ViewModels:ViewModel}}"
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="800">

    <UserControl.Resources>
        <Style TargetType="{x:Type dxg:GridColumn}">
            <Setter Property="Width" Value="50"/>
            <Setter Property="HorizontalHeaderContentAlignment" Value="Center"/>
        </Style>

        <Style TargetType="{x:Type dxg:HeaderItemsControl}">
            <Setter Property="FontWeight" Value="DemiBold"/>
        </Style>
    </UserControl.Resources>

        <!--<dxmvvm:Interaction.Behaviors>
            <dxmvvm:EventToCommand EventName="" Command="{Binding OnLoadedCommand}"/>
        </dxmvvm:Interaction.Behaviors>-->
        <dxg:GridControl ItemsSource="{Binding ItemsTable}"
                     AutoGenerateColumns="AddNew"
                     EnableSmartColumnsGeneration="True">

        <dxmvvm:Interaction.Behaviors >
            <behaviors:DynamicConditionBehavior x:Name="ConditionBehavior" />
            </dxmvvm:Interaction.Behaviors>
            <dxg:GridControl.View>
                <dxg:TableView ShowGroupPanel="False"
                           AllowPerPixelScrolling="True"/>
            </dxg:GridControl.View>
        </dxg:GridControl>
  </UserControl>

Table2DView.xaml

{
 "data": {
  "translations": [
   {
    "translatedText": "مرحبا"
   }
  ]
 }
}