【问题标题】:Show tooltip in LineSeries WinForms Chart?在 LineSeries WinForms 图表中显示工具提示?
【发布时间】:2013-07-31 06:03:20
【问题描述】:

我正在开发一个仪表板系统,我在 WinForms 中使用折线图。我需要在每一行显示 toptip。这个我试过了

var series = new Series
                    {
                        Name = chartPoint.SetName,
                        Color = chartPoint.ChartColor,
                        ChartType = SeriesChartType.Line,
                        BorderDashStyle = chartPoint.ChartDashStyle,
                        BorderWidth = chartPoint.BorderWidth,
                        IsVisibleInLegend = !chartPoint.HideLegend,
                        ToolTip = "Hello World"
                    };

但它不适合我

【问题讨论】:

    标签: c# winforms mschart


    【解决方案1】:

    您有两个选择,要么使用图表控件接受的Keywords

    myChart.Series[0].ToolTip = "Name #SERIESNAME : X - #VALX{F2} , Y - #VALY{F2}";
    

    Chart 控件中,Keyword 是一个字符序列,在运行时被自动计算的值替换。有关图表控件接受的关键字的完整列表,请查找Keyword reference

    如果你想要更奇特的东西,你必须处理事件GetToolTipText

    this.myChart.GetToolTipText += new System.Windows.Forms.DataVisualization.Charting.Chart.ToolTipEventHandler(this.myChart_GetToolTipText);
    

    现在我不确定您想在工具提示上显示什么,但您可以相应地添加逻辑。假设您要显示系列中DataPoints 的值

    private void myChart_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e)
    {
        switch(e.HitTestResult.ChartElementType)
        {  
            case ChartElementType.DataPoint:
                e.Text = myChart.Series[0].Points[e.HitTestResult.PointIndex]).ToString()
                         + /* something for which no keyword exists */;
                break;
            case ChartElementType.Axis:
                // add logic here
            case ....
            .
            .    
            default:
                // do nothing       
        }
    

    【讨论】:

    • @ravi,这对你没有帮助吗??
    【解决方案2】:

    在一些 RnD 之后,我得到了 Line Series 的工具提示,但仍然困惑为什么它不能使用这个解决方案。 这是解决方案

    series.ToolTip = string.Format("Name '{0}' : X - {1} , Y - {2}", chartPoint.SetName, "#VALX{F2}",
                                                   "#VALY{F2}");
            mainChartControl.GetToolTipText += ChartControlGetToolTipText;
    
     private void ChartControlGetToolTipText(object sender, ToolTipEventArgs e)
        {
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多