【问题标题】:Legend box series title, how to highlight other chart series in LightningChart?图例框系列标题,如何在 LightningChart 中突出显示其他图表系列?
【发布时间】:2016-05-21 15:04:17
【问题描述】:

我可以看到,当将鼠标移到 ViewXY 的 LegendBox 中的系列标题上时,系列会突出显示。

我正在使用 WPF 图表。我有几个系列想同时强调。

如何做到这一点?

【问题讨论】:

    标签: wpf graph charts mouseevent legend


    【解决方案1】:

    LegendBox 类有 SeriesTitle* 事件。你可以像这样使用它:

    m_chart.BeginUpdate();
    
    
    ViewXY viewXY = m_chart.ViewXY;
    viewXY.XAxes[0].ValueType = AxisValueType.Number; 
    
    int seriesCount = 10; 
    
    //Create series that will highlight the other series 
    
    for (int i = 0; i < seriesCount; i++)
    {
       PointLineSeries s = new PointLineSeries(viewXY, viewXY.XAxes[0], viewXY.YAxes[0]);
       s.LineStyle.Color = DefaultColors.SeriesForBlackBackgroundWpf[i]; 
       s.Points = GenerateSomeRandomData((i+1) * 20);
       s.Title.Text = "Series " + i.ToString(); 
       viewXY.PointLineSeries.Add(s);
    }
    viewXY.LegendBox.MoveFromSeriesTitle = false;
    viewXY.LegendBox.SeriesTitleMouseClick += LegendBox_SeriesTitleMouseClick;
    viewXY.LegendBox.Layout = LegendBoxLayout.Vertical; 
    
    m_chart.EndUpdate();
    

    并像这样定义事件处理程序:

    void LegendBox_SeriesTitleMouseClick(object sender, System.Windows.RoutedEventArgs e)
        {
            m_chart.BeginUpdate(); 
    
            foreach (PointLineSeries s in m_chart.ViewXY.PointLineSeries)
            {
                s.SetHighlight();
    
                //s.RemoveHighlight(); //To remove highlight, use this 
            }
            m_chart.EndUpdate(); 
        }
    

    然后单击任何系列标题,所有系列都会突出显示。根据 series.MouseHighlight 属性设置,变为更亮的粗线,动画颜色由亮变暗,或保持原色。

    希望这会有所帮助:-)

    【讨论】:

    • 致敬,伙计!这样可行。但是如果我只想在图例中显示其中一些系列,而隐藏其余部分,该怎么做?
    • 您可以通过为您不想在图例框中看到的所有系列设置 series.ShowInLegendBox = false 来做到这一点。
    • 感谢非常有帮助的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多