DevExpress ChartControl ToolTipPointPattern和ToolTipSeriesPattern

原本只是想改一下鼠标放到曲线上的tip显示的小数点位数
然后就发现他这个属性还挺多,多到有点看不懂
然后就写了小demo测试

demo代码

// Create a series and add points to it. 
            Series series1 = new Series("Series 1", ViewType.Line);
            series1.Points.Add(new SeriesPoint("A", new double[] { 4.1111 }));
            series1.Points.Add(new SeriesPoint("B", new double[] { 2.2222 }));
            series1.Points.Add(new SeriesPoint("C", new double[] { 17.7777 }));
            series1.Points.Add(new SeriesPoint("D", new double[] { 4.4444 }));
            series1.Points.Add(new SeriesPoint("E", new double[] { 17.7777 }));
            series1.Points.Add(new SeriesPoint("F", new double[] { 12.2222 }));
            series1.Points.Add(new SeriesPoint("G", new double[] { 15.5555 }));

            // Add the series to the chart. 
            chartControl.Series.Add(series1);

             Disable a crosshair cursor. 
            chartControl.CrosshairEnabled = DefaultBoolean.True;

             Enable chart tooltips.  
            chartControl.ToolTipEnabled = DefaultBoolean.True; 

             Specify the tooltip point pattern. 
            series1.ToolTipPointPattern = "ToolTipPoint: {A}:{V:F2}";
            series1.ToolTipSeriesPattern = "ToolTipSeries: {A}:{V:F2}";
            series1.CrosshairLabelPattern = "CrosshairLabel: {A}:{V:F2}";

demo效果

在这里插入图片描述
在这里插入图片描述

demo结论

结论就很明显了,ToolTipPoint是鼠标放到点上才会显示出来的tip,CrosshairLabel是鼠标放到图上,它会十字线找到点,再显示出来。而最后ToolTipSeriesPattern是干嘛用的,怎样显示出来,我也还没摸清。

Pattern

在这里插入图片描述

附上官方的文档和例程

https://documentation.devexpress.com/WindowsForms/18052/Controls-and-Libraries/Chart-Control/Examples/End-User-Interaction/How-to-Use-Chart-Tooltips

using DevExpress.XtraCharts;
using System;
using System.Windows.Forms;
using DevExpress.Utils;

namespace TooltipCustomization {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            // Create an empty chart. 
            ChartControl chartControl = new ChartControl();

            // Add the chart to the form. 
            chartControl.Dock = DockStyle.Fill;
            this.Controls.Add(chartControl);

            // Create a series and add points to it. 
            Series series1 = new Series("Series 1", ViewType.Bar);
            series1.Points.Add(new SeriesPoint("A", new double[] { 4 }));
            series1.Points.Add(new SeriesPoint("B", new double[] { 2 }));
            series1.Points.Add(new SeriesPoint("C", new double[] { 17 }));
            series1.Points.Add(new SeriesPoint("D", new double[] { 4 }));
            series1.Points.Add(new SeriesPoint("E", new double[] { 17 }));
            series1.Points.Add(new SeriesPoint("F", new double[] { 12 }));
            series1.Points.Add(new SeriesPoint("G", new double[] { 15 }));

            // Add the series to the chart. 
            chartControl.Series.Add(series1);

            // Disable a crosshair cursor. 
            chartControl.CrosshairEnabled = DefaultBoolean.False;

            // Enable chart tooltips.  
            chartControl.ToolTipEnabled = DefaultBoolean.True;

            // Show a tooltip's beak 
            ToolTipController controller = new ToolTipController();
            chartControl.ToolTipController = controller;
            controller.ShowBeak = true;

            // Change the default tooltip mouse position to relative position. 
            ToolTipRelativePosition relativePosition = new ToolTipRelativePosition();
            chartControl.ToolTipOptions.ToolTipPosition = relativePosition;

            // Specify the tooltip relative position offsets.   
            relativePosition.OffsetX = 2;
            relativePosition.OffsetY = 2;

            // Specify the tooltip point pattern. 
            series1.ToolTipPointPattern = "Bar Series: {A}:{V}";
        }
    }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小康师兄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值