Windows演示基础的相关热图

| 谁知道有什么好的工具可以为WPF绘制相关的热图? 基于注释的示例: 原始图像来源     
已邀请:
        免费的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/ (只需点击“热图”按钮)     
        如果您正在寻找商品,我建议您看看Telerik控件。 Telerik对于WPF具有出色的控件。长列表中包括一个热图控件。这是他们列出热图功能的站点的链接: http://www.telerik.com/products/wpf/map.aspx 如果您想构建某些东西,这里有一些博客文章,列出了如何做(提供源): http://www.garrettgirod.com/?p=111 http://www.nickdarnell.com/?p=833     
        Syncfusion图表组件似乎提供了热图。     
        这不是免费的组件,但是如果您可以使用Telerik库,则可以使用以下代码: http://www.telerik.com/products/wpf/heatmap.aspx 过去,我不得不将其用于一些项目,并且效果很好。     
        我将DevExpress与自定义ColorFormatter行为一起使用。我在市场上找不到开箱即用的产品。这花了我几天的时间来开发。我的代码附在下面,希望可以对那里的人有所帮助。 编辑:我使用了POCO视图模型和MVVM,但是您可以根据需要将其更改为不使用POCO。 Table2DViewModel.cs
namespace ViewModel
{
    [POCOViewModel]
    public class Table2DViewModel
    {
        public ITable2DView Table2DView { get; set; }

        public DataTable ItemsTable { get; set; }


        public Table2DViewModel()
        {
        }

        public Table2DViewModel(MainViewModel mainViewModel, ITable2DView table2DView) : base(mainViewModel)
        {
            Table2DView = table2DView;   
            CreateTable();
        }

        private void CreateTable()
        {
            var dt = new DataTable();
            var xAxisStrings = new string[]{\"X1\",\"X2\",\"X3\"};
            var yAxisStrings = new string[]{\"Y1\",\"Y2\",\"Y3\"};

            //TODO determine your min, max number for your colours
            var minValue = 0;
            var maxValue = 100;
            Table2DView.SetColorFormatter(minValue,maxValue, null);

            //Add the columns
            dt.Columns.Add(\" \", typeof(string));
            foreach (var x in xAxisStrings) dt.Columns.Add(x, typeof(double));

            //Add all the values
            double z = 0;
            for (var y = 0; y < yAxisStrings.Length; y++)
            {
                var dr = dt.NewRow();
                dr[\" \"] = yAxisStrings[y];
                for (var x = 0; x < xAxisStrings.Length; x++)
                {
                    //TODO put your actual values here!
                    dr[xAxisStrings[x]] = z++; //Add a random values
                }
                dt.Rows.Add(dr);
            }
            ItemsTable = dt;
        }


        public static Table2DViewModel Create(MainViewModel mainViewModel, ITable2DView table2DView)
        {
            var factory = ViewModelSource.Factory((MainViewModel mainVm, ITable2DView view) => new Table2DViewModel(mainVm, view));
            return factory(mainViewModel, table2DView);
        }
    }

}
ITable2DView.cs
namespace Interfaces
    {
        public interface ITable2DView
        {
            void SetColorFormatter(float minValue, float maxValue, ColorScaleFormat colorScaleFormat);
        }
    }
Table2DView.xaml.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;
        }
    }
}
DynamicConditionBehavior.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,
                });
            }

        }
    }
}
Table2DView.xaml
<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>
    

要回复问题请先登录注册