在Winforms图表中突出显示一个LegendItem

时间:2017-03-08 20:35:30

标签: c# .net winforms charts mschart

正如标题所暗示的那样,我想高亮显示Winforms Chart的一个LegendItem。 (我不想改变系列的颜色!我只想更改LegendItem文本的颜色或LegendItem的BackgroundColor)

我尝试了以下内容,但似乎没有任何改变......

LegendItem legendItem = (LegendItem)result.Object;
legendItem.BorderColor = Color.BlueViolet;
legendItem.MarkerColor = Color.BlueViolet;
legendItem.ShadowColor = Color.BlueViolet;
legendItem.Color = Color.BlueViolet;
legendItem.BackSecondaryColor = Color.BlueViolet;
legendItem.BackImageTransparentColor = Color.BlueViolet;
legendItem.MarkerBorderColor = Color.BlueViolet;
legendItem.SeparatorColor = Color.BlueViolet;

我的问题有解决方案吗?

1 个答案:

答案 0 :(得分:2)

您必须处理CustomizeLegend事件:

    private void chart1_CustomizeLegend(object sender, CustomizeLegendEventArgs e)
    {
        foreach (LegendItem li in e.LegendItems)
        {
            if (li.Cells[1].Text == "Series2")
            {
                li.Cells[1].BackColor = Color.DarkGreen;
                li.Cells[1].ForeColor = Color.White;
            }
        }
    }

enter image description here