Interface IChartLegend
Represents the legend of the chart.
public interface IChartLegend
Properties
AutoPositionX
X positioning is automatic.
bool AutoPositionX { get; set; }
Property Value
AutoPositionY
Y positioning is automatic.
bool AutoPositionY { get; set; }
Property Value
Height
Y-size. 1/4000 of chart plot. IsHMode Shall set to True
int Height { get; set; }
Property Value
IncludeInLayout
Show legend without overlapping. Default is True.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Create chart and set range
IChart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["B2:C6"];
//Set chart type
chart.ChartType = ExcelChartType.Cone3DClustered;
//True to show legend without overlapping the chart
IChartLegend chartLegend = chart.Legend;
chartLegend.IncludeInLayout = true;
//Save to file
workbook.SaveToFile("Chart.xlsx");
bool IncludeInLayout { get; set; }
Property Value
InnerLayoutTarget
bool InnerLayoutTarget { get; set; }
Property Value
IsHMode
false value Specifies that the Height shall be interpreted as the Bottom of the chart element.
bool IsHMode { get; set; }
Property Value
IsVerticalLegend
True if vertical legend (a single column of entries);
False if horizontal legend (multiple columns of entries).
Manual-sized legends always have this bit set to False.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Create chart and set range
IChart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["B2:C6"];
//Set chart type
chart.ChartType = ExcelChartType.Cone3DClustered;
//True if the legend is vertical
if(chart.Legend.IsVerticalLegend){ //Your code here }
//Save to file
workbook.SaveToFile("Chart.xlsx");
bool IsVerticalLegend { get; set; }
Property Value
IsWMode
false value Specifies that the Width shall be interpreted as the Right of the chart element.
bool IsWMode { get; set; }
Property Value
IsXMode
true value Specifies that the X shall be interpreted as the Left of the chart element.
bool IsXMode { get; set; }
Property Value
IsYMode
true value Specifies that the Y shall be interpreted as the Top of the chart element.
bool IsYMode { get; set; }
Property Value
LegendEntries
Represents legend entries collection. Read only.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Create chart and set range
IChart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["B2:C6"];
//Set chart type
chart.ChartType = ExcelChartType.Cone3DClustered;
//Get the count of legend entries
int legendEntriesCount = chart.Legend.LegendEntries.Count;
if(legendEntriesCount != 0){ //Your code here }
//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartLegendEntries LegendEntries { get; }
Property Value
Position
Type:
0 = bottom
1 = corner
2 = top
3 = right
4 = left
7 = not docked or inside the plot area.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Create chart and set range
IChart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["B2:C6"];
//Set chart type
chart.ChartType = ExcelChartType.Cone3DClustered;
//Set the position of legend on the chart
chart.Legend.Position = LegendPositionType.Top;
//Save to file
workbook.SaveToFile("Chart.xlsx");
LegendPositionType Position { get; set; }
Property Value
TextArea
Return text area of legend.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Create chart and set range
IChart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["B2:C6"];
//Set chart type
chart.ChartType = ExcelChartType.Cone3DClustered;
//Set text area for the legend
chart.Legend.TextArea.Color = Color.Gray;
chart.Legend.TextArea.Size = 10;
chart.Legend.TextArea.FontName = "Bernard MT Condensed";
//Save to file
workbook.SaveToFile("Chart.xlsx");
IChartTextArea TextArea { get; }
Property Value
Width
X-size. 1/4000 of chart plot. IsWMode Shall set to True
int Width { get; set; }
Property Value
X
X-position of upper-left corner. 1/4000 of chart plot.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Create chart and set range
IChart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["B2:C6"];
//Set chart type
chart.ChartType = ExcelChartType.Cone3DClustered;
//X co-ordinate of upper-left corner of the legend
chart.Legend.X = -80;
//Save to file
workbook.SaveToFile("Chart.xlsx");
int X { get; set; }
Property Value
Y
Y-position of upper-left corner. 1/4000 of chart plot.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Create chart and set range
IChart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["B2:C6"];
//Set chart type
chart.ChartType = ExcelChartType.Cone3DClustered;
//Y co-ordinate of upper-left corner of the legend
chart.Legend.Y = 30;
//Save to file
workbook.SaveToFile("Chart.xlsx");
int Y { get; set; }
Property Value
Methods
Clear()
Clears chart legend.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Clears the legend of chart
worksheet.Charts[0].Legend.Clear();
//Save to file
workbook.SaveToFile("Chart.xlsx");
void Clear()
Delete()
Deletes chart legend.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Create chart and set range
IChart chart = worksheet.Charts.Add();
chart.DataRange = worksheet.Range["B2:C6"];
//Clears the legend of chart
worksheet.Charts[0].Legend.Delete();
//Save to file
workbook.SaveToFile("Chart.xlsx");
void Delete()