DevExpress的ChartControl控件中Button点击获取当前节点

先看效果:

项目遇到一个业务需求,需要根据双击不同的节点,做不同的操作。

在网上查ChartControl点击事件,发现有一个着重点:ChartControl.RuntimeHitTesting属性一定要设为True。

但是!!!新版的ChartControl.RuntimeHitTesting被弃用了!!!!(头大)

跑去翻官方的API文档,发现这样一个属性:ChartControl.SelectionMode(开心~~~)

官方给的描述是这样的:

Gets or sets a value which specifies how the chart elements are selected.

ChartControl控件中为:

参数说明:

Single:

Only one series element can be selected. Click or tap a series element to select it.

Multiple :

You can select multiple series elements simultaneously. Click or tap a series element to select it. Hold Ctrl and click a series element to deselect it.

Extended:

The Extended mode combines the Single and Multiple selection modes' behaviors.

this.chartControl1.SelectionMode = DevExpress.XtraCharts.ElementSelectionMode.Single;

SO,问题解决了!!

贴源码:

using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void Form1_Load(object sender, EventArgs e)
        {
            double[] hz = { 1, 2, 3, 4};
            double[] zbb = { 9, 8, 7, 6};
            Series series = new Series();
            for (int i = 0; i < hz.Length; i++)
            {
                series.Points.Add(new SeriesPoint(hz[i], zbb[i]));
            }
            chartControl1.Series.Add(series);
        }

        private void chartControl1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ChartHitInfo hitInfo = chartControl1.CalcHitInfo(e.X, e.Y);
            if (hitInfo.SeriesPoint != null)
                MessageBox.Show(hitInfo.SeriesPoint.Argument+","+ hitInfo.SeriesPoint.Values[0]);
            else
                MessageBox.Show("失败了!"); 
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值