libxlsxwriter
|
The Chart object represents an Excel chart. It provides functions for adding data series to the chart and for configuring the chart.
A Chart object isn't created directly. Instead a chart is created by calling the workbook_add_chart()
function from a Workbook object. For example:
The chart in the worksheet will look like this:
The basic procedure for adding a chart to a worksheet is:
workbook_add_chart()
.chart_add_series()
.worksheet_insert_chart()
. Functions | |
lxw_chart_series * | chart_add_series (lxw_chart *chart, const char *categories, const char *values) |
Add a data series to a chart. | |
void | chart_series_set_categories (lxw_chart_series *series, const char *sheetname, lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col) |
Set a series "categories" range using row and column values. | |
void | chart_series_set_values (lxw_chart_series *series, const char *sheetname, lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col) |
Set a series "values" range using row and column values. | |
void | chart_series_set_name (lxw_chart_series *series, const char *name) |
Set the name of a chart series range. | |
void | chart_series_set_name_range (lxw_chart_series *series, const char *sheetname, lxw_row_t row, lxw_col_t col) |
Set a series name formula using row and column values. | |
void | chart_series_set_line (lxw_chart_series *series, lxw_chart_line *line) |
Set the line properties for a chart series. | |
void | chart_series_set_fill (lxw_chart_series *series, lxw_chart_fill *fill) |
Set the fill properties for a chart series. | |
void | chart_series_set_invert_if_negative (lxw_chart_series *series) |
Invert the fill color for negative series values. | |
void | chart_series_set_pattern (lxw_chart_series *series, lxw_chart_pattern *pattern) |
Set the pattern properties for a chart series. | |
void | chart_series_set_marker_type (lxw_chart_series *series, uint8_t type) |
Set the data marker type for a series. | |
void | chart_series_set_marker_size (lxw_chart_series *series, uint8_t size) |
Set the size of a data marker for a series. | |
void | chart_series_set_marker_line (lxw_chart_series *series, lxw_chart_line *line) |
Set the line properties for a chart series marker. | |
void | chart_series_set_marker_fill (lxw_chart_series *series, lxw_chart_fill *fill) |
Set the fill properties for a chart series marker. | |
void | chart_series_set_marker_pattern (lxw_chart_series *series, lxw_chart_pattern *pattern) |
Set the pattern properties for a chart series marker. | |
lxw_error | chart_series_set_points (lxw_chart_series *series, lxw_chart_point *points[]) |
Set the formatting for points in the series. | |
void | chart_series_set_smooth (lxw_chart_series *series, uint8_t smooth) |
Smooth a line or scatter chart series. | |
void | chart_series_set_labels (lxw_chart_series *series) |
Add data labels to a chart series. | |
void | chart_series_set_labels_options (lxw_chart_series *series, uint8_t show_name, uint8_t show_category, uint8_t show_value) |
Set the display options for the labels of a data series. | |
lxw_error | chart_series_set_labels_custom (lxw_chart_series *series, lxw_chart_data_label *data_labels[]) |
Set the properties for data labels in a series. | |
void | chart_series_set_labels_separator (lxw_chart_series *series, uint8_t separator) |
Set the separator for the data label captions. | |
void | chart_series_set_labels_position (lxw_chart_series *series, uint8_t position) |
Set the data label position for a series. | |
void | chart_series_set_labels_leader_line (lxw_chart_series *series) |
Set leader lines for Pie and Doughnut charts. | |
void | chart_series_set_labels_legend (lxw_chart_series *series) |
Set the legend key for a data label in a chart series. | |
void | chart_series_set_labels_percentage (lxw_chart_series *series) |
Set the percentage for a Pie/Doughnut data point. | |
void | chart_series_set_labels_num_format (lxw_chart_series *series, const char *num_format) |
Set the number format for chart data labels in a series. | |
void | chart_series_set_labels_font (lxw_chart_series *series, lxw_chart_font *font) |
Set the font properties for chart data labels in a series. | |
void | chart_series_set_labels_line (lxw_chart_series *series, lxw_chart_line *line) |
Set the line properties for the data labels in a chart series. | |
void | chart_series_set_labels_fill (lxw_chart_series *series, lxw_chart_fill *fill) |
Set the fill properties for the data labels in a chart series. | |
void | chart_series_set_labels_pattern (lxw_chart_series *series, lxw_chart_pattern *pattern) |
Set the pattern properties for the data labels in a chart series. | |
void | chart_series_set_trendline (lxw_chart_series *series, uint8_t type, uint8_t value) |
Turn on a trendline for a chart data series. | |
void | chart_series_set_trendline_forecast (lxw_chart_series *series, double forward, double backward) |
Set the trendline forecast for a chart data series. | |
void | chart_series_set_trendline_equation (lxw_chart_series *series) |
Display the equation of a trendline for a chart data series. | |
void | chart_series_set_trendline_r_squared (lxw_chart_series *series) |
Display the R squared value of a trendline for a chart data series. | |
void | chart_series_set_trendline_intercept (lxw_chart_series *series, double intercept) |
Set the trendline Y-axis intercept for a chart data series. | |
void | chart_series_set_trendline_name (lxw_chart_series *series, const char *name) |
Set the trendline name for a chart data series. | |
void | chart_series_set_trendline_line (lxw_chart_series *series, lxw_chart_line *line) |
Set the trendline line properties for a chart data series. | |
lxw_series_error_bars * | chart_series_get_error_bars (lxw_chart_series *series, lxw_chart_error_bar_axis axis_type) |
Get a pointer to X or Y error bars from a chart series. | |
void | chart_series_set_error_bars (lxw_series_error_bars *error_bars, uint8_t type, double value) |
void | chart_series_set_error_bars_direction (lxw_series_error_bars *error_bars, uint8_t direction) |
Set the direction (up, down or both) of the error bars for a chart series. | |
void | chart_series_set_error_bars_endcap (lxw_series_error_bars *error_bars, uint8_t endcap) |
Set the end cap type for the error bars of a chart series. | |
void | chart_series_set_error_bars_line (lxw_series_error_bars *error_bars, lxw_chart_line *line) |
Set the line properties for a chart series error bars. | |
lxw_chart_axis * | chart_axis_get (lxw_chart *chart, lxw_chart_axis_type axis_type) |
Get an axis pointer from a chart. | |
void | chart_axis_set_name (lxw_chart_axis *axis, const char *name) |
Set the name caption of the an axis. | |
void | chart_axis_set_name_range (lxw_chart_axis *axis, const char *sheetname, lxw_row_t row, lxw_col_t col) |
Set a chart axis name formula using row and column values. | |
void | chart_axis_set_name_font (lxw_chart_axis *axis, lxw_chart_font *font) |
Set the font properties for a chart axis name. | |
void | chart_axis_set_num_font (lxw_chart_axis *axis, lxw_chart_font *font) |
Set the font properties for the numbers of a chart axis. | |
void | chart_axis_set_num_format (lxw_chart_axis *axis, const char *num_format) |
Set the number format for a chart axis. | |
void | chart_axis_set_line (lxw_chart_axis *axis, lxw_chart_line *line) |
Set the line properties for a chart axis. | |
void | chart_axis_set_fill (lxw_chart_axis *axis, lxw_chart_fill *fill) |
Set the fill properties for a chart axis. | |
void | chart_axis_set_pattern (lxw_chart_axis *axis, lxw_chart_pattern *pattern) |
Set the pattern properties for a chart axis. | |
void | chart_axis_set_reverse (lxw_chart_axis *axis) |
Reverse the order of the axis categories or values. | |
void | chart_axis_set_crossing (lxw_chart_axis *axis, double value) |
Set the position that the axis will cross the opposite axis. | |
void | chart_axis_set_crossing_max (lxw_chart_axis *axis) |
Set the opposite axis crossing position as the axis maximum. | |
void | chart_axis_set_crossing_min (lxw_chart_axis *axis) |
Set the opposite axis crossing position as the axis minimum. | |
void | chart_axis_off (lxw_chart_axis *axis) |
Turn off/hide an axis. | |
void | chart_axis_set_position (lxw_chart_axis *axis, uint8_t position) |
Position a category axis on or between the axis tick marks. | |
void | chart_axis_set_label_position (lxw_chart_axis *axis, uint8_t position) |
Position the axis labels. | |
void | chart_axis_set_label_align (lxw_chart_axis *axis, uint8_t align) |
Set the alignment of the axis labels. | |
void | chart_axis_set_min (lxw_chart_axis *axis, double min) |
Set the minimum value for a chart axis. | |
void | chart_axis_set_max (lxw_chart_axis *axis, double max) |
Set the maximum value for a chart axis. | |
void | chart_axis_set_log_base (lxw_chart_axis *axis, uint16_t log_base) |
Set the log base of the axis range. | |
void | chart_axis_set_major_tick_mark (lxw_chart_axis *axis, uint8_t type) |
Set the major axis tick mark type. | |
void | chart_axis_set_minor_tick_mark (lxw_chart_axis *axis, uint8_t type) |
Set the minor axis tick mark type. | |
void | chart_axis_set_interval_unit (lxw_chart_axis *axis, uint16_t unit) |
Set the interval between category values. | |
void | chart_axis_set_interval_tick (lxw_chart_axis *axis, uint16_t unit) |
Set the interval between category tick marks. | |
void | chart_axis_set_major_unit (lxw_chart_axis *axis, double unit) |
Set the increment of the major units in the axis. | |
void | chart_axis_set_minor_unit (lxw_chart_axis *axis, double unit) |
Set the increment of the minor units in the axis. | |
void | chart_axis_set_display_units (lxw_chart_axis *axis, uint8_t units) |
Set the display units for a value axis. | |
void | chart_axis_set_display_units_visible (lxw_chart_axis *axis, uint8_t visible) |
Turn on/off the display units for a value axis. | |
void | chart_axis_major_gridlines_set_visible (lxw_chart_axis *axis, uint8_t visible) |
Turn on/off the major gridlines for an axis. | |
void | chart_axis_minor_gridlines_set_visible (lxw_chart_axis *axis, uint8_t visible) |
Turn on/off the minor gridlines for an axis. | |
void | chart_axis_major_gridlines_set_line (lxw_chart_axis *axis, lxw_chart_line *line) |
Set the line properties for the chart axis major gridlines. | |
void | chart_axis_minor_gridlines_set_line (lxw_chart_axis *axis, lxw_chart_line *line) |
Set the line properties for the chart axis minor gridlines. | |
void | chart_title_set_name (lxw_chart *chart, const char *name) |
Set the title of the chart. | |
void | chart_title_set_name_range (lxw_chart *chart, const char *sheetname, lxw_row_t row, lxw_col_t col) |
Set a chart title formula using row and column values. | |
void | chart_title_set_name_font (lxw_chart *chart, lxw_chart_font *font) |
Set the font properties for a chart title. | |
void | chart_title_off (lxw_chart *chart) |
Turn off an automatic chart title. | |
void | chart_legend_set_position (lxw_chart *chart, uint8_t position) |
Set the position of the chart legend. | |
void | chart_legend_set_font (lxw_chart *chart, lxw_chart_font *font) |
Set the font properties for a chart legend. | |
lxw_error | chart_legend_delete_series (lxw_chart *chart, int16_t delete_series[]) |
Remove one or more series from the the legend. | |
void | chart_chartarea_set_line (lxw_chart *chart, lxw_chart_line *line) |
Set the line properties for a chartarea. | |
void | chart_chartarea_set_fill (lxw_chart *chart, lxw_chart_fill *fill) |
Set the fill properties for a chartarea. | |
void | chart_chartarea_set_pattern (lxw_chart *chart, lxw_chart_pattern *pattern) |
Set the pattern properties for a chartarea. | |
void | chart_plotarea_set_line (lxw_chart *chart, lxw_chart_line *line) |
Set the line properties for a plotarea. | |
void | chart_plotarea_set_fill (lxw_chart *chart, lxw_chart_fill *fill) |
Set the fill properties for a plotarea. | |
void | chart_plotarea_set_pattern (lxw_chart *chart, lxw_chart_pattern *pattern) |
Set the pattern properties for a plotarea. | |
void | chart_set_style (lxw_chart *chart, uint8_t style_id) |
Set the chart style type. | |
void | chart_set_table (lxw_chart *chart) |
Turn on a data table below the horizontal axis. | |
void | chart_set_table_grid (lxw_chart *chart, uint8_t horizontal, uint8_t vertical, uint8_t outline, uint8_t legend_keys) |
Turn on/off grid options for a chart data table. | |
void | chart_set_up_down_bars (lxw_chart *chart) |
Turn on up-down bars for the chart. | |
void | chart_set_up_down_bars_format (lxw_chart *chart, lxw_chart_line *up_bar_line, lxw_chart_fill *up_bar_fill, lxw_chart_line *down_bar_line, lxw_chart_fill *down_bar_fill) |
Turn on up-down bars for the chart, with formatting. | |
void | chart_set_drop_lines (lxw_chart *chart, lxw_chart_line *line) |
Turn on and format Drop Lines for a chart. | |
void | chart_set_high_low_lines (lxw_chart *chart, lxw_chart_line *line) |
Turn on and format high-low Lines for a chart. | |
void | chart_set_series_overlap (lxw_chart *chart, int8_t overlap) |
Set the overlap between series in a Bar/Column chart. | |
void | chart_set_series_gap (lxw_chart *chart, uint16_t gap) |
Set the gap between series in a Bar/Column chart. | |
void | chart_show_blanks_as (lxw_chart *chart, uint8_t option) |
Set the option for displaying blank data in a chart. | |
void | chart_show_hidden_data (lxw_chart *chart) |
Display data on charts from hidden rows or columns. | |
void | chart_set_rotation (lxw_chart *chart, uint16_t rotation) |
Set the Pie/Doughnut chart rotation. | |
void | chart_set_hole_size (lxw_chart *chart, uint8_t size) |
Set the Doughnut chart hole size. | |
lxw_chart_series * chart_add_series | ( | lxw_chart * | chart, |
const char * | categories, | ||
const char * | values | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
categories | The range of categories in the data series. |
values | The range of values in the data series. |
In Excel a chart series is a collection of information that defines which data is plotted such as the categories and values. It is also used to define the formatting for the data.
For an libxlsxwriter chart object the chart_add_series()
function is used to set the categories and values of the series:
The series parameters are:
categories
: This sets the chart category labels. The category is more or less the same as the X axis. In most Excel chart types the categories
property is optional and the chart will just assume a sequential series from 1..n
:values
: This is the most important property of a series and is the only mandatory option for every chart object. This parameter links the chart with the worksheet data that it displays.The categories
and values
should be a string formula like "=Sheet1!$A$2:$A$7"
in the same way it is represented in Excel. This is convenient when recreating a chart from an example in Excel but it is trickier to generate programmatically. For these cases you can set the categories
and values
to NULL
and use the chart_series_set_categories()
and chart_series_set_values()
functions:
As shown in the previous example the return value from chart_add_series()
is a lxw_chart_series pointer. This can be used in other functions that configure a series.
More than one series can be added to a chart. The series numbering and order in the Excel chart will be the same as the order in which they are added in libxlsxwriter:
It is also possible to specify non-contiguous ranges:
void chart_series_set_categories | ( | lxw_chart_series * | series, |
const char * | sheetname, | ||
lxw_row_t | first_row, | ||
lxw_col_t | first_col, | ||
lxw_row_t | last_row, | ||
lxw_col_t | last_col | ||
) |
series | A series object created via chart_add_series() . |
sheetname | The name of the worksheet that contains the data range. |
first_row | The first row of the range. (All zero indexed.) |
first_col | The first column of the range. |
last_row | The last row of the range. |
last_col | The last col of the range. |
The categories
and values
of a chart data series are generally set using the chart_add_series()
function and Excel range formulas like "=Sheet1!$A$2:$A$7"
.
The chart_series_set_categories()
function is an alternative method that is easier to generate programmatically. It requires that you set the categories
and values
parameters in chart_add_series()
to NULL
and then set them using row and column values in chart_series_set_categories()
and chart_series_set_values()
:
void chart_series_set_values | ( | lxw_chart_series * | series, |
const char * | sheetname, | ||
lxw_row_t | first_row, | ||
lxw_col_t | first_col, | ||
lxw_row_t | last_row, | ||
lxw_col_t | last_col | ||
) |
series | A series object created via chart_add_series() . |
sheetname | The name of the worksheet that contains the data range. |
first_row | The first row of the range. (All zero indexed.) |
first_col | The first column of the range. |
last_row | The last row of the range. |
last_col | The last col of the range. |
The categories
and values
of a chart data series are generally set using the chart_add_series()
function and Excel range formulas like "=Sheet1!$A$2:$A$7"
.
The chart_series_set_values()
function is an alternative method that is easier to generate programmatically. See the documentation for chart_series_set_categories()
above.
void chart_series_set_name | ( | lxw_chart_series * | series, |
const char * | name | ||
) |
series | A series object created via chart_add_series() . |
name | The series name. |
The chart_series_set_name
function is used to set the name for a chart data series. The series name in Excel is displayed in the chart legend and in the formula bar. The name property is optional and if it isn't supplied it will default to Series 1..n
.
The function applies to a lxw_chart_series object created using chart_add_series()
:
The name parameter can also be a formula such as =Sheet1!$A$1
to point to a cell in the workbook that contains the name:
See also the chart_series_set_name_range()
function to see how to set the name formula programmatically.
void chart_series_set_name_range | ( | lxw_chart_series * | series, |
const char * | sheetname, | ||
lxw_row_t | row, | ||
lxw_col_t | col | ||
) |
series | A series object created via chart_add_series() . |
sheetname | The name of the worksheet that contains the cell range. |
row | The zero indexed row number of the range. |
col | The zero indexed column number of the range. |
The chart_series_set_name_range()
function can be used to set a series name range and is an alternative to using chart_series_set_name()
and a string formula:
void chart_series_set_line | ( | lxw_chart_series * | series, |
lxw_chart_line * | line | ||
) |
series | A series object created via chart_add_series() . |
line | A lxw_chart_line struct. |
Set the line/border properties of a chart series:
For more information see Chart formatting: Line.
void chart_series_set_fill | ( | lxw_chart_series * | series, |
lxw_chart_fill * | fill | ||
) |
series | A series object created via chart_add_series() . |
fill | A lxw_chart_fill struct. |
Set the fill properties of a chart series:
For more information see Chart formatting: Fill.
void chart_series_set_invert_if_negative | ( | lxw_chart_series * | series | ) |
series | A series object created via chart_add_series() . |
Invert the fill color for negative values. Usually only applicable to column and bar charts.
void chart_series_set_pattern | ( | lxw_chart_series * | series, |
lxw_chart_pattern * | pattern | ||
) |
series | A series object created via chart_add_series() . |
pattern | A lxw_chart_pattern struct. |
Set the pattern properties of a chart series:
For more information see lxw_chart_pattern_type and Chart formatting: Pattern.
void chart_series_set_marker_type | ( | lxw_chart_series * | series, |
uint8_t | type | ||
) |
series | A series object created via chart_add_series() . |
type | The marker type, see lxw_chart_marker_type. |
In Excel a chart marker is used to distinguish data points in a plotted series. In general only Line and Scatter and Radar chart types use markers. The libxlsxwriter chart types that can have markers are:
The chart types with MARKERS
in the name have markers with default colors and shapes turned on by default but it is possible using the various chart_series_set_marker_xxx()
functions below to change these defaults. It is also possible to turn on an off markers.
The chart_series_set_marker_type()
function is used to specify the type of the series marker:
The available marker types defined by lxw_chart_marker_type are:
The #LXW_CHART_MARKER_NONE
type can be used to turn off default markers:
The #LXW_CHART_MARKER_AUTOMATIC
type is a special case which turns on a marker using the default marker style for the particular series. If automatic is on then other marker properties such as size, line or fill cannot be set.
void chart_series_set_marker_size | ( | lxw_chart_series * | series, |
uint8_t | size | ||
) |
series | A series object created via chart_add_series() . |
size | The size of the marker. |
The chart_series_set_marker_size()
function is used to specify the size of the series marker:
void chart_series_set_marker_line | ( | lxw_chart_series * | series, |
lxw_chart_line * | line | ||
) |
series | A series object created via chart_add_series() . |
line | A lxw_chart_line struct. |
Set the line/border properties of a chart marker:
For more information see Chart formatting: Line.
void chart_series_set_marker_fill | ( | lxw_chart_series * | series, |
lxw_chart_fill * | fill | ||
) |
series | A series object created via chart_add_series() . |
fill | A lxw_chart_fill struct. |
Set the fill properties of a chart marker:
See the example and image above and also see Chart formatting: Fill.
void chart_series_set_marker_pattern | ( | lxw_chart_series * | series, |
lxw_chart_pattern * | pattern | ||
) |
series | A series object created via chart_add_series() . |
pattern | A lxw_chart_pattern struct. |
Set the pattern properties of a chart marker:
For more information see lxw_chart_pattern_type and Chart formatting: Pattern.
lxw_error chart_series_set_points | ( | lxw_chart_series * | series, |
lxw_chart_point * | points[] | ||
) |
series | A series object created via chart_add_series() . |
points | An NULL terminated array of lxw_chart_point pointers. |
In general formatting is applied to an entire series in a chart. However, it is occasionally required to format individual points in a series. In particular this is required for Pie/Doughnut charts where each segment is represented by a point.
For more details see Working with Chart Points
void chart_series_set_smooth | ( | lxw_chart_series * | series, |
uint8_t | smooth | ||
) |
series | A series object created via chart_add_series() . |
smooth | Turn off/on the line smoothing. (0/1) |
The chart_series_set_smooth()
function is used to set the smooth property of a line series. It is only applicable to the line and scatter chart types:
void chart_series_set_labels | ( | lxw_chart_series * | series | ) |
series | A series object created via chart_add_series() . |
The chart_series_set_labels()
function is used to turn on data labels for a chart series. Data labels indicate the values of the plotted data points.
By default data labels are displayed in Excel with only the values shown:
However, it is possible to configure other display options, as shown in the functions below.
For more information see Working with Chart Data Labels.
void chart_series_set_labels_options | ( | lxw_chart_series * | series, |
uint8_t | show_name, | ||
uint8_t | show_category, | ||
uint8_t | show_value | ||
) |
series | A series object created via chart_add_series() . |
show_name | Turn on/off the series name in the label caption. |
show_category | Turn on/off the category name in the label caption. |
show_value | Turn on/off the value in the label caption. |
The chart_series_set_labels_options()
function is used to set the parameters that are displayed in the series data label:
For more information see Working with Chart Data Labels.
lxw_error chart_series_set_labels_custom | ( | lxw_chart_series * | series, |
lxw_chart_data_label * | data_labels[] | ||
) |
series | A series object created via chart_add_series() . |
data_labels | An NULL terminated array of lxw_chart_data_label pointers. |
The chart_series_set_labels_custom()
function is used to set the properties for data labels in a series. It can also be used to delete individual data labels in a series.
In general properties are set for all the data labels in a chart series. However, it is also possible to set properties for individual data labels in a series using chart_series_set_labels_custom()
.
The chart_series_set_labels_custom()
function takes a pointer to an array of lxw_chart_data_label pointers. The list should be NULL
terminated:
For more details see Custom Chart Data Labels.
void chart_series_set_labels_separator | ( | lxw_chart_series * | series, |
uint8_t | separator | ||
) |
series | A series object created via chart_add_series() . |
separator | The separator for the data label options: lxw_chart_label_separator. |
The chart_series_set_labels_separator()
function is used to change the separator between multiple data label items. The default options is a comma separator as shown in the previous example.
The available options are:
For example:
For more information see Working with Chart Data Labels.
void chart_series_set_labels_position | ( | lxw_chart_series * | series, |
uint8_t | position | ||
) |
series | A series object created via chart_add_series() . |
position | The data label position: lxw_chart_label_position. |
The chart_series_set_labels_position()
function sets the position of the labels in the data series:
In Excel the allowable data label positions vary for different chart types. The allowable, and default, positions are:
Position | Line, Scatter | Bar, Column | Pie, Doughnut | Area, Radar |
---|---|---|---|---|
LXW_CHART_LABEL_POSITION_CENTER | Yes | Yes | Yes | Yes (default) |
LXW_CHART_LABEL_POSITION_RIGHT | Yes (default) | |||
LXW_CHART_LABEL_POSITION_LEFT | Yes | |||
LXW_CHART_LABEL_POSITION_ABOVE | Yes | |||
LXW_CHART_LABEL_POSITION_BELOW | Yes | |||
LXW_CHART_LABEL_POSITION_INSIDE_BASE | Yes | |||
LXW_CHART_LABEL_POSITION_INSIDE_END | Yes | Yes | ||
LXW_CHART_LABEL_POSITION_OUTSIDE_END | Yes (default) | Yes | ||
LXW_CHART_LABEL_POSITION_BEST_FIT | Yes (default) |
For more information see Working with Chart Data Labels.
void chart_series_set_labels_leader_line | ( | lxw_chart_series * | series | ) |
series | A series object created via chart_add_series() . |
The chart_series_set_labels_leader_line()
function is used to turn on leader lines for the data label of a series. It is mainly used for pie or doughnut charts:
For more information see Working with Chart Data Labels.
void chart_series_set_labels_legend | ( | lxw_chart_series * | series | ) |
series | A series object created via chart_add_series() . |
The chart_series_set_labels_legend()
function is used to set the legend key for a data series:
For more information see Working with Chart Data Labels.
void chart_series_set_labels_percentage | ( | lxw_chart_series * | series | ) |
series | A series object created via chart_add_series() . |
The chart_series_set_labels_percentage()
function is used to turn on the display of data labels as a percentage for a series. It is mainly used for pie charts:
For more information see Working with Chart Data Labels.
void chart_series_set_labels_num_format | ( | lxw_chart_series * | series, |
const char * | num_format | ||
) |
series | A series object created via chart_add_series() . |
num_format | The number format string. |
The chart_series_set_labels_num_format()
function is used to set the number format for data labels:
The number format is similar to the Worksheet Cell Format num_format, see format_set_num_format()
.
For more information see Working with Chart Data Labels.
void chart_series_set_labels_font | ( | lxw_chart_series * | series, |
lxw_chart_font * | font | ||
) |
series | A series object created via chart_add_series() . |
font | A pointer to a chart lxw_chart_font font struct. |
The chart_series_set_labels_font()
function is used to set the font for data labels:
For more information see Chart formatting: Fonts and Working with Chart Data Labels.
void chart_series_set_labels_line | ( | lxw_chart_series * | series, |
lxw_chart_line * | line | ||
) |
series | A series object created via chart_add_series() . |
line | A lxw_chart_line struct. |
Set the line/border properties of the data labels in a chart series:
For more information see Chart formatting: Line and Working with Chart Data Labels.
void chart_series_set_labels_fill | ( | lxw_chart_series * | series, |
lxw_chart_fill * | fill | ||
) |
series | A series object created via chart_add_series() . |
fill | A lxw_chart_fill struct. |
Set the fill properties of the data labels in a chart series:
See the example and image above and also see Chart formatting: Fill and Working with Chart Data Labels.
void chart_series_set_labels_pattern | ( | lxw_chart_series * | series, |
lxw_chart_pattern * | pattern | ||
) |
series | A series object created via chart_add_series() . |
pattern | A lxw_chart_pattern struct. |
Set the pattern properties of the data labels in a chart series:
For more information see lxw_chart_pattern_type and Chart formatting: Pattern.
void chart_series_set_trendline | ( | lxw_chart_series * | series, |
uint8_t | type, | ||
uint8_t | value | ||
) |
series | A series object created via chart_add_series() . |
type | The type of trendline: lxw_chart_trendline_type. |
value | The order/period value for polynomial and moving average trendlines. |
A trendline can be added to a chart series to indicate trends in the data such as a moving average or a polynomial fit. The trendlines types are shown in the following Excel dialog:
The chart_series_set_trendline()
function turns on these trendlines for a data series:
The value
parameter corresponds to order for a polynomial trendline and period for a Moving Average trendline. It both cases it must be >= 2. The value
parameter is ignored for all other trendlines:
The allowable values for the the trendline type
are:
value
parameter corresponds to order.value
parameter corresponds to period.Other trendline options, such as those shown in the following Excel dialog, can be set using the functions below.
For more information see Working with Chart Trendlines.
void chart_series_set_trendline_forecast | ( | lxw_chart_series * | series, |
double | forward, | ||
double | backward | ||
) |
series | A series object created via chart_add_series() . |
forward | The forward period. |
backward | The backwards period. |
The chart_series_set_trendline_forecast()
function sets the forward and backward forecast periods for the trendline:
For more information see Working with Chart Trendlines.
void chart_series_set_trendline_equation | ( | lxw_chart_series * | series | ) |
series | A series object created via chart_add_series() . |
The chart_series_set_trendline_equation()
function displays the equation of the trendline on the chart:
For more information see Working with Chart Trendlines.
void chart_series_set_trendline_r_squared | ( | lxw_chart_series * | series | ) |
series | A series object created via chart_add_series() . |
The chart_series_set_trendline_r_squared()
function displays the R-squared value for the trendline on the chart:
For more information see Working with Chart Trendlines.
void chart_series_set_trendline_intercept | ( | lxw_chart_series * | series, |
double | intercept | ||
) |
series | A series object created via chart_add_series() . |
intercept | Y-axis intercept value. |
The chart_series_set_trendline_intercept()
function sets the Y-axis intercept for the trendline:
As can be seen from the equation on the chart the intercept point (when X=0) is the same as the value set in the equation.
For more information see Working with Chart Trendlines.
void chart_series_set_trendline_name | ( | lxw_chart_series * | series, |
const char * | name | ||
) |
series | A series object created via chart_add_series() . |
name | The name of the trendline to display in the legend. |
The chart_series_set_trendline_name()
function sets the name of the trendline that is displayed in the chart legend. In the examples above the trendlines are displayed with default names like "Linear (Series 1)" and "2 per Mov. Avg. (Series 1)". If these names are too verbose or not descriptive enough you can set your own trendline name:
It is often preferable to turn off the trendline caption in the legend. This is down in Excel by deleting the trendline name from the legend. In libxlsxwriter this is done using the chart_legend_delete_series()
function to delete the zero based series numbers:
For more information see Working with Chart Trendlines.
void chart_series_set_trendline_line | ( | lxw_chart_series * | series, |
lxw_chart_line * | line | ||
) |
series | A series object created via chart_add_series() . |
line | A lxw_chart_line struct. |
The chart_series_set_trendline_line()
function is used to set the line properties of a trendline:
For more information see Working with Chart Trendlines and Chart formatting: Line.
lxw_series_error_bars * chart_series_get_error_bars | ( | lxw_chart_series * | series, |
lxw_chart_error_bar_axis | axis_type | ||
) |
series | A series object created via chart_add_series() . |
axis_type | The axis type (X or Y): lxw_chart_error_bar_axis. |
The chart_series_get_error_bars()
function returns a pointer to the error bars of a series based on the type of lxw_chart_error_bar_axis:
Note, the series error bars can also be accessed directly:
void chart_series_set_error_bars | ( | lxw_series_error_bars * | error_bars, |
uint8_t | type, | ||
double | value | ||
) |
Set the X or Y error bars for a chart series.
error_bars | A pointer to the series X or Y error bars. |
type | The type of error bar: lxw_chart_error_bar_type. |
value | The error value. |
Error bars can be added to a chart series to indicate error bounds in the data. The error bars can be vertical y_error_bars
(the most common type) or horizontal x_error_bars
(for Bar and Scatter charts only).
The chart_series_set_error_bars()
function sets the error bar type and value associated with the type:
The error bar types that be used are:
All error bar types, apart from Standard error, should have a valid value to set the error range:
For the Standard error type the value is ignored.
For more information see Working with Chart Error Bars.
void chart_series_set_error_bars_direction | ( | lxw_series_error_bars * | error_bars, |
uint8_t | direction | ||
) |
error_bars | A pointer to the series X or Y error bars. |
direction | The bar direction: lxw_chart_error_bar_direction. |
The chart_series_set_error_bars_direction()
function sets the direction of the error bars:
The valid directions are:
For more information see Working with Chart Error Bars.
void chart_series_set_error_bars_endcap | ( | lxw_series_error_bars * | error_bars, |
uint8_t | endcap | ||
) |
error_bars | A pointer to the series X or Y error bars. |
endcap | The error bar end cap type: lxw_chart_error_bar_cap . |
The chart_series_set_error_bars_endcap()
function sets the end cap type for the error bars:
The valid values are:
For more information see Working with Chart Error Bars.
void chart_series_set_error_bars_line | ( | lxw_series_error_bars * | error_bars, |
lxw_chart_line * | line | ||
) |
error_bars | A pointer to the series X or Y error bars. |
line | A lxw_chart_line struct. |
The chart_series_set_error_bars_line()
function sets the line properties for the error bars:
For more information see Chart formatting: Line and Working with Chart Error Bars.
lxw_chart_axis * chart_axis_get | ( | lxw_chart * | chart, |
lxw_chart_axis_type | axis_type | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
axis_type | The axis type (X or Y): lxw_chart_axis_type. |
The chart_axis_get()
function returns a pointer to a chart axis based on the lxw_chart_axis_type:
Note, the axis pointer can also be accessed directly:
void chart_axis_set_name | ( | lxw_chart_axis * | axis, |
const char * | name | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
name | The name caption of the axis. |
The chart_axis_set_name()
function sets the name (also known as title or caption) for an axis. It can be used for the X or Y axes. The name is displayed below an X axis and to the side of a Y axis.
The name parameter can also be a formula such as =Sheet1!$A$1
to point to a cell in the workbook that contains the name:
See also the chart_axis_set_name_range()
function to see how to set the name formula programmatically.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_name_range | ( | lxw_chart_axis * | axis, |
const char * | sheetname, | ||
lxw_row_t | row, | ||
lxw_col_t | col | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
sheetname | The name of the worksheet that contains the cell range. |
row | The zero indexed row number of the range. |
col | The zero indexed column number of the range. |
The chart_axis_set_name_range()
function can be used to set an axis name range and is an alternative to using chart_axis_set_name()
and a string formula:
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_name_font | ( | lxw_chart_axis * | axis, |
lxw_chart_font * | font | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
font | A pointer to a chart lxw_chart_font font struct. |
The chart_axis_set_name_font()
function is used to set the font of an axis name:
For more information see Chart formatting: Fonts.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_num_font | ( | lxw_chart_axis * | axis, |
lxw_chart_font * | font | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
font | A pointer to a chart lxw_chart_font font struct. |
The chart_axis_set_num_font()
function is used to set the font of the numbers on an axis:
For more information see Chart formatting: Fonts.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_num_format | ( | lxw_chart_axis * | axis, |
const char * | num_format | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
num_format | The number format string. |
The chart_axis_set_num_format()
function is used to set the format of the numbers on an axis:
The number format is similar to the Worksheet Cell Format num_format, see format_set_num_format()
.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_line | ( | lxw_chart_axis * | axis, |
lxw_chart_line * | line | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
line | A lxw_chart_line struct. |
Set the line properties of a chart axis:
For more information see Chart formatting: Line.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_fill | ( | lxw_chart_axis * | axis, |
lxw_chart_fill * | fill | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
fill | A lxw_chart_fill struct. |
Set the fill properties of a chart axis:
For more information see Chart formatting: Fill.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_pattern | ( | lxw_chart_axis * | axis, |
lxw_chart_pattern * | pattern | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
pattern | A lxw_chart_pattern struct. |
Set the pattern properties of a chart axis:
For more information see lxw_chart_pattern_type and Chart formatting: Pattern.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_reverse | ( | lxw_chart_axis * | axis | ) |
axis | A pointer to a chart lxw_chart_axis object. |
Reverse the order of the axis categories or values:
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_crossing | ( | lxw_chart_axis * | axis, |
double | value | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
value | The category or value that the axis crosses at. |
Set the position that the axis will cross the opposite axis:
If crossing is omitted (the default) the crossing will be set automatically by Excel based on the chart data.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_crossing_max | ( | lxw_chart_axis * | axis | ) |
axis | A pointer to a chart lxw_chart_axis object. |
Set the position that the opposite axis will cross as the axis maximum. The default axis crossing position is generally the axis minimum so this function can be used to reverse the location of the axes without reversing the number sequence:
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_crossing_min | ( | lxw_chart_axis * | axis | ) |
axis | A pointer to a chart lxw_chart_axis object. |
Set the position that the opposite axis will cross as the axis minimum. The default axis crossing position is generally the axis minimum so this function can be used to reverse the location of the axes without reversing the number sequence:
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_off | ( | lxw_chart_axis * | axis | ) |
axis | A pointer to a chart lxw_chart_axis object. |
Turn off, hide, a chart axis:
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_position | ( | lxw_chart_axis * | axis, |
uint8_t | position | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
position | A lxw_chart_axis_tick_position value. |
Position a category axis horizontally on, or between, the axis tick marks.
There are two allowable values:
Axis types: This function is applicable to category axes only. See Chart Value and Category Axes.
void chart_axis_set_label_position | ( | lxw_chart_axis * | axis, |
uint8_t | position | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
position | A lxw_chart_axis_label_position value. |
Position the axis labels for the chart. The labels are the numbers, or strings or dates, on the axis that indicate the categories or values of the axis.
For example:
The allowable values:
The LXW_CHART_AXIS_LABEL_POSITION_NONE turns off the axis labels. This is slightly different from chart_axis_off()
which also turns off the labels but also turns off tick marks.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_label_align | ( | lxw_chart_axis * | axis, |
uint8_t | align | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
align | A lxw_chart_axis_label_alignment value. |
Position the category axis labels for the chart. The labels are the numbers, or strings or dates, on the axis that indicate the categories of the axis.
The allowable values:
Axis types: This function is applicable to category axes only. See Chart Value and Category Axes.
void chart_axis_set_min | ( | lxw_chart_axis * | axis, |
double | min | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
min | Minimum value for chart axis. Value axes only. |
Set the minimum value for the axis range.
Axis types: This function is applicable to value and date axes only. See Chart Value and Category Axes.
void chart_axis_set_max | ( | lxw_chart_axis * | axis, |
double | max | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
max | Maximum value for chart axis. Value axes only. |
Set the maximum value for the axis range.
See the above image.
Axis types: This function is applicable to value and date axes only. See Chart Value and Category Axes.
void chart_axis_set_log_base | ( | lxw_chart_axis * | axis, |
uint16_t | log_base | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
log_base | The log base for value axis. Value axes only. |
Set the log base for the axis:
The allowable range of values for the log base in Excel is between 2 and 1000.
Axis types: This function is applicable to value axes only. See Chart Value and Category Axes.
void chart_axis_set_major_tick_mark | ( | lxw_chart_axis * | axis, |
uint8_t | type | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
type | The tick mark type, defined by lxw_chart_tick_mark. |
Set the type of the major axis tick mark:
The tick mark types are:
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_minor_tick_mark | ( | lxw_chart_axis * | axis, |
uint8_t | type | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
type | The tick mark type, defined by lxw_chart_tick_mark. |
Set the type of the minor axis tick mark:
See the image and example above.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_set_interval_unit | ( | lxw_chart_axis * | axis, |
uint16_t | unit | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
unit | The interval between the categories. |
Set the interval between the category values. The default interval is 1 which gives the intervals shown in the charts above:
1, 2, 3, 4, 5, etc.
Setting it to 2 gives:
1, 3, 5, 7, etc.
For example:
Axis types: This function is applicable to category and date axes only. See Chart Value and Category Axes.
void chart_axis_set_interval_tick | ( | lxw_chart_axis * | axis, |
uint16_t | unit | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
unit | The interval between the category ticks. |
Set the interval between the category tick marks. The default interval is 1 between each category but it can be set to other integer values:
Axis types: This function is applicable to category and date axes only. See Chart Value and Category Axes.
void chart_axis_set_major_unit | ( | lxw_chart_axis * | axis, |
double | unit | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
unit | The increment of the major units. |
Set the increment of the major units in the axis range.
Axis types: This function is applicable to value and date axes only. See Chart Value and Category Axes.
void chart_axis_set_minor_unit | ( | lxw_chart_axis * | axis, |
double | unit | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
unit | The increment of the minor units. |
Set the increment of the minor units in the axis range.
See the image above
Axis types: This function is applicable to value and date axes only. See Chart Value and Category Axes.
void chart_axis_set_display_units | ( | lxw_chart_axis * | axis, |
uint8_t | units | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
units | The display units: lxw_chart_axis_display_unit. |
Set the display units for the axis. This can be useful if the axis numbers are very large but you don't want to represent them in scientific notation:
Axis types: This function is applicable to value axes only. See Chart Value and Category Axes.
void chart_axis_set_display_units_visible | ( | lxw_chart_axis * | axis, |
uint8_t | visible | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
visible | Turn off/on the display units. (0/1) |
Turn on or off the display units for the axis. This option is set on automatically by chart_axis_set_display_units()
.
Axis types: This function is applicable to value axes only. See Chart Value and Category Axes.
void chart_axis_major_gridlines_set_visible | ( | lxw_chart_axis * | axis, |
uint8_t | visible | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
visible | Turn off/on the major gridline. (0/1) |
Turn on or off the major gridlines for an X or Y axis. In most Excel charts the Y axis major gridlines are on by default and the X axis major gridlines are off by default.
Example:
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_minor_gridlines_set_visible | ( | lxw_chart_axis * | axis, |
uint8_t | visible | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
visible | Turn off/on the minor gridline. (0/1) |
Turn on or off the minor gridlines for an X or Y axis. In most Excel charts the X and Y axis minor gridlines are off by default.
Example, turn on all major and minor gridlines:
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_major_gridlines_set_line | ( | lxw_chart_axis * | axis, |
lxw_chart_line * | line | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
line | A lxw_chart_line struct. |
Format the line properties of the major gridlines of a chart:
For more information see Chart formatting: Line.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_axis_minor_gridlines_set_line | ( | lxw_chart_axis * | axis, |
lxw_chart_line * | line | ||
) |
axis | A pointer to a chart lxw_chart_axis object. |
line | A lxw_chart_line struct. |
Format the line properties of the minor gridlines of a chart, see the example above.
For more information see Chart formatting: Line.
Axis types: This function is applicable to to all axes types. See Chart Value and Category Axes.
void chart_title_set_name | ( | lxw_chart * | chart, |
const char * | name | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
name | The chart title name. |
The chart_title_set_name()
function sets the name (title) for the chart. The name is displayed above the chart.
The name parameter can also be a formula such as =Sheet1!$A$1
to point to a cell in the workbook that contains the name:
See also the chart_title_set_name_range()
function to see how to set the name formula programmatically.
The Excel default is to have no chart title.
void chart_title_set_name_range | ( | lxw_chart * | chart, |
const char * | sheetname, | ||
lxw_row_t | row, | ||
lxw_col_t | col | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
sheetname | The name of the worksheet that contains the cell range. |
row | The zero indexed row number of the range. |
col | The zero indexed column number of the range. |
The chart_title_set_name_range()
function can be used to set a chart title range and is an alternative to using chart_title_set_name()
and a string formula:
void chart_title_set_name_font | ( | lxw_chart * | chart, |
lxw_chart_font * | font | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
font | A pointer to a chart lxw_chart_font font struct. |
The chart_title_set_name_font()
function is used to set the font of a chart title:
In Excel a chart title font is bold by default (as shown in the image above). To turn off bold in the font you cannot use LXW_FALSE (0) since that is indistinguishable from an uninitialized value. Instead you should use LXW_EXPLICIT_FALSE:
For more information see Chart formatting: Fonts.
void chart_title_off | ( | lxw_chart * | chart | ) |
chart | Pointer to a lxw_chart instance to be configured. |
In general in Excel a chart title isn't displayed unless the user explicitly adds one. However, Excel adds an automatic chart title to charts with a single series and a user defined series name. The chart_title_off()
function allows you to turn off this automatic chart title:
void chart_legend_set_position | ( | lxw_chart * | chart, |
uint8_t | position | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
position | The lxw_chart_legend_position value for the legend. |
The chart_legend_set_position()
function is used to set the chart legend to one of the lxw_chart_legend_position values:
LXW_CHART_LEGEND_NONE LXW_CHART_LEGEND_RIGHT LXW_CHART_LEGEND_LEFT LXW_CHART_LEGEND_TOP LXW_CHART_LEGEND_BOTTOM LXW_CHART_LEGEND_TOP_RIGHT LXW_CHART_LEGEND_OVERLAY_RIGHT LXW_CHART_LEGEND_OVERLAY_LEFT LXW_CHART_LEGEND_OVERLAY_TOP_RIGHT
For example:
This function can also be used to turn off a chart legend:
void chart_legend_set_font | ( | lxw_chart * | chart, |
lxw_chart_font * | font | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
font | A pointer to a chart lxw_chart_font font struct. |
The chart_legend_set_font()
function is used to set the font of a chart legend:
For more information see Chart formatting: Fonts.
chart | Pointer to a lxw_chart instance to be configured. |
delete_series | An array of zero-indexed values to delete from series. |
The chart_legend_delete_series()
function allows you to remove/hide one or more series in a chart legend (the series will still display on the chart).
This function takes an array of one or more zero indexed series numbers. The array should be terminated with -1.
For example to remove the first and third zero-indexed series from the legend of a chart with 3 series:
void chart_chartarea_set_line | ( | lxw_chart * | chart, |
lxw_chart_line * | line | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
line | A lxw_chart_line struct. |
Set the line/border properties of a chartarea. In Excel the chartarea is the background area behind the chart:
For more information see Chart formatting: Line.
void chart_chartarea_set_fill | ( | lxw_chart * | chart, |
lxw_chart_fill * | fill | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
fill | A lxw_chart_fill struct. |
Set the fill properties of a chartarea:
See the example and image above.
For more information see Chart formatting: Fill.
void chart_chartarea_set_pattern | ( | lxw_chart * | chart, |
lxw_chart_pattern * | pattern | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
pattern | A lxw_chart_pattern struct. |
Set the pattern properties of a chartarea:
For more information see lxw_chart_pattern_type and Chart formatting: Pattern.
void chart_plotarea_set_line | ( | lxw_chart * | chart, |
lxw_chart_line * | line | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
line | A lxw_chart_line struct. |
Set the line/border properties of a plotarea. In Excel the plotarea is the area between the axes on which the chart series are plotted:
For more information see Chart formatting: Line.
void chart_plotarea_set_fill | ( | lxw_chart * | chart, |
lxw_chart_fill * | fill | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
fill | A lxw_chart_fill struct. |
Set the fill properties of a plotarea:
See the example and image above.
For more information see Chart formatting: Fill.
void chart_plotarea_set_pattern | ( | lxw_chart * | chart, |
lxw_chart_pattern * | pattern | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
pattern | A lxw_chart_pattern struct. |
Set the pattern properties of a plotarea:
For more information see lxw_chart_pattern_type and Chart formatting: Pattern.
void chart_set_style | ( | lxw_chart * | chart, |
uint8_t | style_id | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
style_id | An index representing the chart style, 1 - 48. |
The chart_set_style()
function is used to set the style of the chart to one of the 48 built-in styles available on the "Design" tab in Excel 2007:
The style index number is counted from 1 on the top left in the Excel dialog. The default style is 2.
Note:
In Excel 2013 the Styles section of the "Design" tab in Excel shows what were referred to as "Layouts" in previous versions of Excel. These layouts are not defined in the file format. They are a collection of modifications to the base chart type. They can not be defined by the chart_set_style()
` function.
void chart_set_table | ( | lxw_chart * | chart | ) |
chart | Pointer to a lxw_chart instance to be configured. |
The chart_set_table()
function adds a data table below the horizontal axis with the data used to plot the chart:
The data table can only be shown with Bar, Column, Line and Area charts.
void chart_set_table_grid | ( | lxw_chart * | chart, |
uint8_t | horizontal, | ||
uint8_t | vertical, | ||
uint8_t | outline, | ||
uint8_t | legend_keys | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
horizontal | Turn on/off the horizontal grid lines in the table. |
vertical | Turn on/off the vertical grid lines in the table. |
outline | Turn on/off the outline lines in the table. |
legend_keys | Turn on/off the legend keys in the table. |
The chart_set_table_grid()
function turns on/off grid options for a chart data table. The data table grid options in Excel are shown in the dialog below:
These options can be passed to the chart_set_table_grid()
function. The values for a default chart are:
horizontal
: On.vertical
: On.outline
: On.legend_keys
: Off.Example:
The data table can only be shown with Bar, Column, Line and Area charts.
void chart_set_up_down_bars | ( | lxw_chart * | chart | ) |
chart | Pointer to a lxw_chart instance to be configured. |
The chart_set_up_down_bars()
function adds Up-Down bars to Line charts to indicate the difference between the first and last data series:
Up-Down bars are only available in Line charts. By default Up-Down bars are black and white like in the above example. To format the border or fill of the bars see the chart_set_up_down_bars_format()
function below.
void chart_set_up_down_bars_format | ( | lxw_chart * | chart, |
lxw_chart_line * | up_bar_line, | ||
lxw_chart_fill * | up_bar_fill, | ||
lxw_chart_line * | down_bar_line, | ||
lxw_chart_fill * | down_bar_fill | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
up_bar_line | A lxw_chart_line struct for the up-bar border. |
up_bar_fill | A lxw_chart_fill struct for the up-bar fill. |
down_bar_line | A lxw_chart_line struct for the down-bar border. |
down_bar_fill | A lxw_chart_fill struct for the down-bar fill. |
The chart_set_up_down_bars_format()
function adds Up-Down bars to Line charts to indicate the difference between the first and last data series. It also allows the up and down bars to be formatted:
Up-Down bars are only available in Line charts. For more format information see Chart formatting: Line and Chart formatting: Fill.
void chart_set_drop_lines | ( | lxw_chart * | chart, |
lxw_chart_line * | line | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
line | A lxw_chart_line struct. |
The chart_set_drop_lines()
function adds Drop Lines to charts to show the Category value of points in the data:
It is possible to format the Drop Line line properties if required:
Drop Lines are only available in Line and Area charts. For more format information see Chart formatting: Line.
void chart_set_high_low_lines | ( | lxw_chart * | chart, |
lxw_chart_line * | line | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
line | A lxw_chart_line struct. |
The chart_set_high_low_lines()
function adds High-Low Lines to charts to show the Category value of points in the data:
It is possible to format the High-Low Line line properties if required:
High-Low Lines are only available in Line charts. For more format information see Chart formatting: Line.
void chart_set_series_overlap | ( | lxw_chart * | chart, |
int8_t | overlap | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
overlap | The overlap between the series. -100 to 100. |
The chart_set_series_overlap()
function sets the overlap between series in Bar and Column charts.
The overlap value must be in the range 0 <= overlap <= 500
. The default value is 0.
This option is only available for Bar/Column charts.
void chart_set_series_gap | ( | lxw_chart * | chart, |
uint16_t | gap | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
gap | The gap between the series. 0 to 500. |
The chart_set_series_gap()
function sets the gap between series in Bar and Column charts.
The gap value must be in the range 0 <= gap <= 500
. The default value is 150.
This option is only available for Bar/Column charts.
void chart_show_blanks_as | ( | lxw_chart * | chart, |
uint8_t | option | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
option | The display option. A lxw_chart_blank option. |
The chart_show_blanks_as()
function controls how blank data is displayed in a chart:
The option
parameter can have one of the following values:
void chart_show_hidden_data | ( | lxw_chart * | chart | ) |
chart | Pointer to a lxw_chart instance to be configured. |
Display data that is in hidden rows or columns on the chart:
void chart_set_rotation | ( | lxw_chart * | chart, |
uint16_t | rotation | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
rotation | The angle of rotation. |
The chart_set_rotation()
function is used to set the rotation of the first segment of a Pie/Doughnut chart. This has the effect of rotating the entire chart:
The angle of rotation must be in the range 0 <= rotation <= 360
.
This option is only available for Pie/Doughnut charts.
void chart_set_hole_size | ( | lxw_chart * | chart, |
uint8_t | size | ||
) |
chart | Pointer to a lxw_chart instance to be configured. |
size | The hole size as a percentage. |
The chart_set_hole_size()
function is used to set the hole size of a Doughnut chart:
The hole size must be in the range 10 <= size <= 90
.
This option is only available for Doughnut charts.
typedef enum lxw_chart_line_dash_type lxw_chart_line_dash_type |
The dash types are shown in the order that they appear in the Excel dialog. See Chart formatting: Line.
typedef struct lxw_chart_line lxw_chart_line |
typedef struct lxw_chart_fill lxw_chart_fill |
typedef struct lxw_chart_pattern lxw_chart_pattern |
typedef struct lxw_chart_font lxw_chart_font |
typedef struct lxw_chart_point lxw_chart_point |
The lxw_chart_point used to set the line, fill and pattern of one or more points in a chart data series. See Working with Chart Points.
typedef struct lxw_chart_data_label lxw_chart_data_label |
The lxw_chart_data_label struct is used to represent a data label in a chart series so that custom properties can be set for it.
typedef struct lxw_chart_series lxw_chart_series |
The lxw_chart_series is created using the chart_add_series function. It is used in functions that modify a chart series but the members of the struct aren't modified directly.
typedef struct lxw_chart_axis lxw_chart_axis |
The lxw_chart_axis struct is used in functions that modify a chart axis but the members of the struct aren't modified directly.
enum lxw_chart_type |
The dash types are shown in the order that they appear in the Excel dialog. See Chart formatting: Line.
enum lxw_chart_axis_type |
enum lxw_chart_blank |
Data Structures | |
struct | lxw_chart_line |
Struct to represent a chart line. More... | |
struct | lxw_chart_fill |
Struct to represent a chart fill. More... | |
struct | lxw_chart_pattern |
Struct to represent a chart pattern. More... | |
struct | lxw_chart_font |
Struct to represent a chart font. More... | |
struct | lxw_chart_point |
Struct to represent an Excel chart data point. More... | |
struct | lxw_chart_data_label |
Struct to represent an Excel chart data label. More... | |
struct | lxw_chart_series |
Struct to represent an Excel chart data series. More... | |
struct | lxw_chart_axis |
Struct to represent an Excel chart axis. More... | |
struct | lxw_chart |
Struct to represent an Excel chart. More... | |
Typedefs | |
typedef enum lxw_chart_type | lxw_chart_type |
Available chart types. | |
typedef enum lxw_chart_legend_position | lxw_chart_legend_position |
Chart legend positions. | |
typedef enum lxw_chart_line_dash_type | lxw_chart_line_dash_type |
Chart line dash types. | |
typedef enum lxw_chart_marker_type | lxw_chart_marker_type |
Chart marker types. | |
typedef enum lxw_chart_pattern_type | lxw_chart_pattern_type |
Chart pattern types. | |
typedef enum lxw_chart_label_position | lxw_chart_label_position |
Chart data label positions. | |
typedef enum lxw_chart_label_separator | lxw_chart_label_separator |
Chart data label separator. | |
typedef enum lxw_chart_axis_type | lxw_chart_axis_type |
Chart axis types. | |
typedef enum lxw_chart_axis_tick_position | lxw_chart_axis_tick_position |
Axis positions for category axes. | |
typedef enum lxw_chart_axis_label_position | lxw_chart_axis_label_position |
Axis label positions. | |
typedef enum lxw_chart_axis_label_alignment | lxw_chart_axis_label_alignment |
Axis label alignments. | |
typedef enum lxw_chart_axis_display_unit | lxw_chart_axis_display_unit |
Display units for chart value axis. | |
typedef enum lxw_chart_axis_tick_mark | lxw_chart_tick_mark |
Tick mark types for an axis. | |
typedef struct lxw_chart_line | lxw_chart_line |
Struct to represent a chart line. | |
typedef struct lxw_chart_fill | lxw_chart_fill |
Struct to represent a chart fill. | |
typedef struct lxw_chart_pattern | lxw_chart_pattern |
Struct to represent a chart pattern. | |
typedef struct lxw_chart_font | lxw_chart_font |
Struct to represent a chart font. | |
typedef struct lxw_chart_point | lxw_chart_point |
Struct to represent an Excel chart data point. | |
typedef struct lxw_chart_data_label | lxw_chart_data_label |
Struct to represent an Excel chart data label. | |
typedef enum lxw_chart_blank | lxw_chart_blank |
Define how blank values are displayed in a chart. | |
typedef enum lxw_chart_error_bar_type | lxw_chart_error_bar_type |
Type/amount of data series error bar. | |
typedef enum lxw_chart_error_bar_direction | lxw_chart_error_bar_direction |
Direction for a data series error bar. | |
typedef enum lxw_chart_error_bar_axis | lxw_chart_error_bar_axis |
Direction for a data series error bar. | |
typedef enum lxw_chart_error_bar_cap | lxw_chart_error_bar_cap |
End cap styles for a data series error bar. | |
typedef enum lxw_chart_trendline_type | lxw_chart_trendline_type |
Series trendline/regression types. | |
typedef struct lxw_chart_series | lxw_chart_series |
Struct to represent an Excel chart data series. | |
typedef struct lxw_chart_axis | lxw_chart_axis |
Struct to represent an Excel chart axis. | |
typedef struct lxw_chart | lxw_chart |
Struct to represent an Excel chart. | |