• C# Teechart 鼠标悬停 显示数据


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication2
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
                this.tChart1.Series[0].Add(1, 2);
                this.tChart1.Series[0].Add(2, 6);
                this.tChart1.Series[0].Add(6, 3);
            }
            private double xval;
            private void cursorTool1_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e)
            {
                try
                {
                    xval = e.XValue;
                    tChart1.Header.Text = "";
                    for (int i = 0; i < tChart1.Series.Count; i++)
                        if (tChart1.Series[i] is Steema.TeeChart.Styles.Custom)
                        {
                            tChart1.Header.Text += tChart1.Series[i].Title + ": Y(" + e.XValue.ToString("0.00") + ")= ";
                            tChart1.Header.Text += InterpolateLineSeries(tChart1.Series[i] as Steema.TeeChart.Styles.Custom, e.XValue).ToString("0.00") + "
    ";
                        }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
    
    
    
            private double InterpolateLineSeries(Steema.TeeChart.Styles.Custom series, double xvalue)
            {
                return InterpolateLineSeries(series, series.FirstVisibleIndex, series.LastVisibleIndex, xvalue);
            }
    
            /// <summary>
            /// Calculate y=y(x) for arbitrary x. Works fine only for line series with ordered x values.
            /// </summary>
            /// <param name="series"></param>
            /// <param name="firstindex"></param>
            /// <param name="lastindex"></param>
            /// <param name="xvalue"></param>
            /// <returns>y=y(xvalue) where xvalue is arbitrary x value.</returns>
            private double InterpolateLineSeries(Steema.TeeChart.Styles.Custom series, int firstindex, int lastindex, double xvalue)
            {
                try
                {
                    int index;
                    for (index = firstindex; index <= lastindex; index++)
                    {
                        if (index == -1 || series.XValues.Value[index] > xvalue) break;
                    }
                    // safeguard
                    if (index < 1) index = 1;
                    else if (index >= series.Count) index = series.Count - 1;
                    // y=(y2-y1)/(x2-x1)*(x-x1)+y1
                    double dx = series.XValues[index] - series.XValues[index - 1];
                    double dy = series.YValues[index] - series.YValues[index - 1];
                    if (dx != 0.0) return dy * (xvalue - series.XValues[index - 1]) / dx + series.YValues[index - 1];
                    else return 0.0;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return 0.0;
                }
            }
    
    
    
    
    
    
    
    
    
        }
    }
    

      

  • 相关阅读:
    P1351 联合权值
    c++ 贪心讲解大礼包
    取石子 找规律
    树 dfs暴力判环 题意转化
    P2519 [HAOI2011]problem a
    P1640 [SCOI2010]连续攻击游戏 二分图最大匹配 匈牙利算法
    P2756 飞行员配对方案问题 二分图匹配 匈牙利算法
    cogs 49. 跳马问题 DFS dp
    cogs 2. 旅行计划 dijkstra+打印路径小技巧
    cogs 1440. [NOIP2013]积木大赛 贪心水题
  • 原文地址:https://www.cnblogs.com/lierjie/p/5892426.html
Copyright © 2020-2023  润新知