码迷,mamicode.com
首页 > 其他好文 > 详细

MS Chart 折线图点击数据点时显示其值

时间:2018-04-28 15:56:31      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:ati   res   box   send   com   ext   span   format   class   

对于MS Chart当鼠标移动到数据点时或鼠标点击数据点时显示其点的值(X,Y)值

 public partial class Form1 : Form
    {

        System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs toolTipEventArgs;

        public Form1()
        {
            InitializeComponent();
        }


        //鼠标移动到数据点时显示点的数值
        private void chart1_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e)
        {
            toolTipEventArgs = e;

            if (e.HitTestResult.ChartElementType == System.Windows.Forms.DataVisualization.Charting.ChartElementType.DataPoint)
            {
                int i = e.HitTestResult.PointIndex;
                System.Windows.Forms.DataVisualization.Charting.DataPoint dp = e.HitTestResult.Series.Points[i];
                e.Text = string.Format("次数:{0},数值:{1}", dp.XValue.ToString(), dp.YValues[0]);
            }

        }

        //鼠标点击数据点时得到数据点的值
        private void chart1_Click(object sender, EventArgs e)
        {
            if (toolTipEventArgs.HitTestResult.PointIndex < 0)
            {
                return;
            }
            if (toolTipEventArgs.HitTestResult.ChartElementType == System.Windows.Forms.DataVisualization.Charting.ChartElementType.DataPoint)
            {
                int i = toolTipEventArgs.HitTestResult.PointIndex;
                System.Windows.Forms.DataVisualization.Charting.DataPoint dp = toolTipEventArgs.HitTestResult.Series.Points[i];
                textBox1.Text = dp.XValue.ToString();
                textBox2.Text = dp.YValues[0].ToString();
            }

        }
    }

 

MS Chart 折线图点击数据点时显示其值

标签:ati   res   box   send   com   ext   span   format   class   

原文地址:https://www.cnblogs.com/YuanDong1314/p/8967672.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!