Click or drag to resize

IChartLegend Properties

The IChartLegend type exposes the following members.

Properties
Name Description
Public property AutoPositionX
X positioning is automatic.
Public property AutoPositionY
Y positioning is automatic.
Public property Height
Y-size. 1/4000 of chart plot. IsHMode Shall set to True
Public property Code example IncludeInLayout
Show legend without overlapping. Default is True.
Examples
The following code illustrates use of IncludeInLayout property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Create chart and set range</para><para>IChart chart = worksheet.Charts.Add();</para><para>chart.DataRange = worksheet.Range["B2:C6"];</para><para>//Set chart type</para><para>chart.ChartType = ExcelChartType.Cone3DClustered;</para><para>//True to show legend without overlapping the chart</para><para>IChartLegend chartLegend = chart.Legend;</para><para>chartLegend.IncludeInLayout = true;</para><para>//Save to file</para><para>workbook.SaveToFile("Chart.xlsx");</para>
Public property InnerLayoutTarget
Gets or sets a value indicating whether the layout target is intended to be used internally.
Public property IsHMode
false value Specifies that the Height shall be interpreted as the Bottom of the chart element.
Public property Code example 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.
Examples
The following code illustrates use of IsVerticalLegend property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Create chart and set range</para><para>IChart chart = worksheet.Charts.Add();</para><para>chart.DataRange = worksheet.Range["B2:C6"];</para><para>//Set chart type</para><para>chart.ChartType = ExcelChartType.Cone3DClustered;</para><para>//True if the legend is vertical</para><para>if(chart.Legend.IsVerticalLegend){ //Your code here }</para><para>//Save to file</para><para>workbook.SaveToFile("Chart.xlsx");</para>
Public property IsWMode
false value Specifies that the Width shall be interpreted as the Right of the chart element.
Public property IsXMode
true value Specifies that the X shall be interpreted as the Left of the chart element.
Public property IsYMode
true value Specifies that the Y shall be interpreted as the Top of the chart element.
Public property Code example LegendEntries
Represents legend entries collection. Read only.
Examples
The following code illustrates use of LegendEntries property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Create chart and set range</para><para>IChart chart = worksheet.Charts.Add();</para><para>chart.DataRange = worksheet.Range["B2:C6"];</para><para>//Set chart type</para><para>chart.ChartType = ExcelChartType.Cone3DClustered;</para><para>//Get the count of legend entries</para><para>int legendEntriesCount = chart.Legend.LegendEntries.Count;</para><para>if(legendEntriesCount != 0){ //Your code here }</para><para>//Save to file</para><para>workbook.SaveToFile("Chart.xlsx");</para>
Public property Code example Position
Type: 0 = bottom 1 = corner 2 = top 3 = right 4 = left 7 = not docked or inside the plot area.
Examples
The following code illustrates use of Position property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Create chart and set range</para><para>IChart chart = worksheet.Charts.Add();</para><para>chart.DataRange = worksheet.Range["B2:C6"];</para><para>//Set chart type</para><para>chart.ChartType = ExcelChartType.Cone3DClustered;</para><para>//Set the position of legend on the chart</para><para>chart.Legend.Position = LegendPositionType.Top;</para><para>//Save to file</para><para>workbook.SaveToFile("Chart.xlsx");</para>
Public property Code example TextArea
Return text area of legend.
Examples
The following code illustrates use of TextArea property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Create chart and set range</para><para>IChart chart = worksheet.Charts.Add();</para><para>chart.DataRange = worksheet.Range["B2:C6"];</para><para>//Set chart type</para><para>chart.ChartType = ExcelChartType.Cone3DClustered;</para><para>//Set text area for the legend</para><para>chart.Legend.TextArea.Color = Color.Gray;</para><para>chart.Legend.TextArea.Size = 10;</para><para>chart.Legend.TextArea.FontName = "Bernard MT Condensed";</para><para>//Save to file</para><para>workbook.SaveToFile("Chart.xlsx");</para>
Public property Width
X-size. 1/4000 of chart plot. IsWMode Shall set to True
Public property Code example X
X-position of upper-left corner. 1/4000 of chart plot.
Examples
The following code illustrates use of X co-ordinate of upper-left corner of the legend:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Create chart and set range</para><para>IChart chart = worksheet.Charts.Add();</para><para>chart.DataRange = worksheet.Range["B2:C6"];</para><para>//Set chart type</para><para>chart.ChartType = ExcelChartType.Cone3DClustered;</para><para>//X co-ordinate of upper-left corner of the legend</para><para>chart.Legend.X = -80;</para><para>//Save to file</para><para>workbook.SaveToFile("Chart.xlsx");</para>
Public property Code example Y
Y-position of upper-left corner. 1/4000 of chart plot.
Examples
The following code illustrates use of Y co-ordinate of upper-left corner of the legend:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Create chart and set range</para><para>IChart chart = worksheet.Charts.Add();</para><para>chart.DataRange = worksheet.Range["B2:C6"];</para><para>//Set chart type</para><para>chart.ChartType = ExcelChartType.Cone3DClustered;</para><para>//Y co-ordinate of upper-left corner of the legend</para><para>chart.Legend.Y = 30;</para><para>//Save to file</para><para>workbook.SaveToFile("Chart.xlsx");</para>
Top
See Also