I am using the System.Windows.Forms.DataVisualization.Charting.Chart
class to draw a chart with some data.
Now I want to suppress the automatic generation of entries within the legend and replace them with custom items. I have already found the way to add custom items but no way of suppressing the autogeneration.
My Code:
var legend = new Legend();
legend.LegendStyle = LegendStyle.Table;
legend.TableStyle = LegendTableStyle.Wide;
legend.IsEquallySpacedItems = true;
legend.IsTextAutoFit = true;
legend.BackColor = Color.White;
legend.Font = new Font(Config.FontFamily, 9);
legend.Docking = Docking.Bottom;
legend.Alignment = StringAlignment.Center;
legend.CustomItems.Add(new LegendItem("test", Color.Green, string.Empty));
ch.Legends.Add(legend);
Has anyone done something like this before?
Try doing it in this event:
I know this is old but wanted to post this here in case someone wants a slightly different way to go about it, this is based off of Steve Wellens answer but instead of adding the items in the event it just removes the non custom ones.
Go to the
Series
collection in the chart properties, and find theIsVisibleInLegend
property and set it tofalse