Change Label Color in a Chart Control

无人久伴 提交于 2019-12-11 08:25:51

问题


The question I have seems to be simple but I can't find an answer around the Internet for that and even trying around did not help me.

I just want to change the color of a Legend (from a Series). I know how to change the text color but I need to change the color of that marker.

 chart1.Legends["1"].ForeColor = Color.Transparent;
 chart1.Legends["1"].BackColor = Color.Transparent;

does not help

Is this possible?

Thank you!

EDIT:

I want to change the blue color to another. Hope this is more clear now.


回答1:


The markers show the ChartType and the Color of all the Series.

Unfortunately the default LegendItems anre hidden and can't be changed, only expanded.

So your best bet, except avoiding the issue by picking a a different green, (if that is why you want to change the blue) would be to clear or disable the default Legend and create a new one from scratch.

For this you can style all sorts of things including setting MarkerStyles and also Bitmaps you create on the fly..

Here and here are two examples that show you how to do it..

And here is one with a rather extended custom Legend

Instead of creating a new Legend you can also hide the LegendItem for a Series

series1.IsVisibleInLegend = true;

and add a new one but it will be added at the end..

Here is an example of adding a simple LegendItem:

void AddLegendItem(Legend L, Series s, Color mc)
{
    LegendItem lit = new LegendItem();

    lit.BorderColor = mc;
    lit.Color = mc;
    lit.SeriesName = s.Name;
    lit.Name = s.Name;
    L.CustomItems.Add(lit);
 }


来源:https://stackoverflow.com/questions/40788189/change-label-color-in-a-chart-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!