为了提高C1Chart WPF的大数据展现性能,特别是在Line和Symbol类型的Charts中,系统预设了一个办法:即我们可以通过设置 DataSeries.RenderMode属性为RenderMode.Bitmap实现。

然而当设置RenderMode.Bitmap后,Tooltips和PlotElementLoaded 事件就失效了。

本篇博文介绍的方法, 在一个散点图中,通过RenderMode的属性设置为”Bitmap”来显示ToolTips:

ToolTipInChart

 

实现的原理很简单:在Chart上增加ChartPanel 图层,再添加ChartPanelObject 即可。

 

实施步骤:

下面是完整的代码:

  1: var pnl = new ChartPanel();
  2:  
  3: var obj = new ChartPanelObject()
  4: {
  5:  HorizontalAlignment = HorizontalAlignment.Right,
  6:  VerticalAlignment = VerticalAlignment.Bottom
  7: };
  8:  
  9: var bdr = new Border()
 10: {
 11:  Background = new SolidColorBrush(Colors.Blue) { Opacity = 0.6 },
 12:  BorderBrush = new SolidColorBrush(Colors.Blue),
 13:  BorderThickness = new Thickness(1, 1, 3, 3),
 14:  CornerRadius = new CornerRadius(6, 6, 0, 6),
 15:  Padding = new Thickness(3)
 16: };
 17:  
 18: var sp = new StackPanel();
 19:  
 20: var tb1 = new TextBlock();
 21: var bind1 = new Binding();
 22: bind1.Source = obj;
 23: bind1.StringFormat = "x={0:#.##}";
 24: bind1.Path = new PropertyPath("DataPoint.X");
 25: tb1.SetBinding(TextBlock.TextProperty, bind1);
 26:  
 27: var tb2 = new TextBlock();
 28: var bind2 = new Binding();
 29: bind2.Source = obj;
 30: bind2.StringFormat = "y={0:#.##}";
 31: bind2.Path = new PropertyPath("DataPoint.Y");
 32: tb2.SetBinding(TextBlock.TextProperty, bind2);
 33:  
 34: sp.Children.Add(tb1);
 35: sp.Children.Add(tb2);
 36:  
 37: bdr.Child = sp;
 38:  
 39: obj.Content = bdr;
 40: obj.DataPoint = new Point();
 41: obj.Action = ChartPanelAction.MouseMove;
 42: obj.Attach = ChartPanelAttach.DataXY;
 43:  
 44: pnl.Children.Add(obj);
 45:  
 46: chart.View.Layers.Add(pnl);
 47: 

 

源码下载: