【问题标题】:Show series value over any point on chart using tooltip c#使用工具提示 c# 在图表上的任何点上显示系列值
【发布时间】:2012-12-05 05:55:40
【问题描述】:

所以我看到了很多关于使用工具提示显示图表数据的示例,当鼠标悬停在数据点上时,但我希望在鼠标悬停在图表上而不一定在特定数据点上时显示值(即其他地方的空白)。我最终还希望在数据点本身上有一个小圆圈或正方形,但这可能会在以后出现。谁能告诉我该怎么做?我将在下面包含我当前的代码。

 private void chData_MouseMove(object sender, MouseEventArgs e)
    {            
        HitTestResult pos = chData.HitTest(e.X, e.Y);
        if (pos.ChartElementType == ChartElementType.DataPoint)
        {
            string tipInfo;
            tipInfo = "Bat 1: " + ch1Array[pos.PointIndex].ToString("0.00") + Environment.NewLine + "Bat 2: " + ch2Array[pos.PointIndex].ToString("0.00") + Environment.NewLine;                
            tooltip.SetToolTip(chData, tipInfo);    
        }

    }

我猜我必须更改 if 语句参数,但我不确定是什么。
非常感谢任何帮助!

【问题讨论】:

    标签: c# charts tooltip hittest


    【解决方案1】:

    所以解决方案是不使用 HitTest。相反,如果您使用 PixelPositionToValue 效果会更好。我将包括下面的代码。

    private void chData_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {   
                int cursorX = Convert.ToInt32(chData.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X));
    
                tipInfo = "Bat 1: " + ch1Array[cursorX].ToString("0.00") + Environment.NewLine + "Bat 2: " + ch2Array[cursorX].ToString("0.00") + Environment.NewLine;
    
                tooltip.SetToolTip(chData, tipInfo);
    
            }
            catch { }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      相关资源
      最近更新 更多