Miguel Moura
Miguel Moura

Reputation: 39484

Microsoft Chart. Legend Appears on Top of X Axis

I created an Microsoft Chart in C# and added the following legend:

Legend legend = new Legend { 
  Alignment = StringAlignment.Center,
  Docking = Docking.Bottom,
  Enabled = true,
  IsDockedInsideChartArea = false,
  TableStyle = LegendTableStyle.Wide,  
};

Part of the legend appears on top of the X axis ... Any idea why?

How can I solve this? Can I add a top margin to the legend?

Thank You, Miguel

Upvotes: 1

Views: 8359

Answers (2)

nbernier
nbernier

Reputation: 1

you need to create a chart area:

p_Chart.ChartAreas.Add(new ChartArea(MAIN_CHART_AREA));

then set both your series and you legend to this area:

legend.DockedToChartArea = MAIN_CHART_AREA;

series.ChartArea = MAIN_CHART_AREA;

Upvotes: 0

Chris Zeh
Chris Zeh

Reputation: 924

In my code I let the Chart create the legend object itself, this is the VB code, but maybe it's useful to you:

aChart.Legends.Clear()
aChart.Legends.Add("Default")
aChart.Legends(0).BorderColor = Color.Black
aChart.Legends(0).Docking = Docking.Bottom
aChart.Legends(0).IsDockedInsideChartArea = False
aChart.Legends(0).TableStyle = LegendTableStyle.Wide
aChart.Legends(0).Alignment = StringAlignment.Center

Upvotes: 2

Related Questions