回复 1楼kyb11111的帖子
你可以自定义Tooltip,当鼠标Hover的时候,将自定义的Tooltip展示出来。
主要是在C1Chart的View层添加一个ChartPanel,然后把你需要展示的数据放到这个Panel里。
代码参考:
- var pnl = new ChartPanel();
- var obj = new ChartPanelObject()
- {
- HorizontalAlignment = HorizontalAlignment.Right,
- VerticalAlignment = VerticalAlignment.Bottom
- };
- var bdr = new Border()
- {
- Background = new SolidColorBrush(Colors.LightYellow) { Opacity = 0.6 },
- BorderBrush = new SolidColorBrush(Colors.Black),
- BorderThickness = new Thickness(1, 1, 2, 2),
- Padding = new Thickness(3)
- };
- var sp = new StackPanel();
- var tb1 = new TextBlock();
- var bind1 = new Binding();
- bind1.Source = obj;
- bind1.StringFormat = "x={0:#.##}";
- bind1.Path = new PropertyPath("DataPoint.X");
- tb1.SetBinding(TextBlock.TextProperty, bind1);
- var tb2 = new TextBlock();
- var bind2 = new Binding();
- bind2.Source = obj;
- bind2.StringFormat = "y={0:#.##}";
- bind2.Path = new PropertyPath("DataPoint.Y");
- tb2.SetBinding(TextBlock.TextProperty, bind2);
- var lb0 = new TextBlock();
- lb0.Text = "Value";
- lb0.FontSize = 12;
- lb0.FontWeight = FontWeights.Bold;
- lb0.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
- var lb1 = new TextBlock();
- lb1.Text = "Description";
- lb1.FontSize = 12;
- lb1.FontWeight = FontWeights.Bold;
- lb1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
- var lb2 = new TextBlock();
- lb2.Text = "Test";
- lb2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
- sp.Children.Add(lb0);
- sp.Children.Add(tb1);
- sp.Children.Add(tb2);
- sp.Children.Add(lb1);
- sp.Children.Add(lb2);
- bdr.Child = sp;
- obj.Content = bdr;
- obj.DataPoint = new Point();
- obj.Action = ChartPanelAction.MouseMove;
- obj.Attach = ChartPanelAttach.DataXY;
- pnl.Children.Add(obj);
- this.c1Chart1.View.Layers.Add(pnl);
复制代码
另外可以参考我们的中文博客,C1Chart在WPF平台下画ToolTips:
http://blog.gcpowertools.com.cn/ ... -in-c1wpfchart.aspx |