UmyaSpreadsheet.ChartFunctions (umya_spreadsheet_ex v0.7.0)
View SourceFunctions for creating and manipulating charts in a spreadsheet.
Summary
Functions
Adds a chart to a spreadsheet.
Adds a chart to a spreadsheet with advanced options.
Adds a chart to a spreadsheet with advanced options, including chart-specific options.
Sets 3D view properties for a chart.
Sets axis titles for a chart.
Sets data labels for a chart.
Sets the legend position for a chart.
Sets the chart style.
Functions
Adds a chart to a spreadsheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetchart_type
- The type of chart (e.g., "bar", "line", "pie")from_cell
- The top-left cell of the chart positionto_cell
- The bottom-right cell of the chart positiontitle
- The title of the chartdata_series
- A list of data series rangesseries_titles
- A list of series titlespoint_titles
- A list of point titles (categories)
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ChartFunctions.add_chart(
spreadsheet,
"Sheet1",
"bar",
"E2",
"K15",
"Sales Chart",
["B2:B10"],
["Sales"],
["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"]
)
Adds a chart to a spreadsheet with advanced options.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetchart_type
- The type of chart (e.g., "bar", "line", "pie")from_cell
- The top-left cell of the chart positionto_cell
- The bottom-right cell of the chart positiontitle
- The title of the chartdata_series
- A list of data series rangesseries_titles
- A list of series titlespoint_titles
- A list of point titles (categories)style
- Chart style numbervary_colors
- Boolean indicating whether to vary colors by pointview_3d
- 3D view options (rotation, perspective)legend
- Legend options (position, overlay)axes
- Axes options (titles, formatting)data_labels
- Data label options
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ChartFunctions.add_chart_with_options(
spreadsheet,
"Sheet1",
"bar",
"E2",
"K15",
"Sales Chart",
["B2:B10"],
["Sales"],
["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"],
2,
true,
%{rot_x: 30, rot_y: 20, perspective: 30, height_percent: 100},
%{position: "right", overlay: false},
%{category_axis_title: "Month", value_axis_title: "Amount"},
%{show_values: true, show_percent: false, show_category_name: false, show_series_name: true, position: "outside_end"}
)
Adds a chart to a spreadsheet with advanced options, including chart-specific options.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetchart_type
- The type of chart (e.g., "bar", "line", "pie")from_cell
- The top-left cell of the chart positionto_cell
- The bottom-right cell of the chart positiontitle
- The title of the chartdata_series
- A list of data series rangesseries_titles
- A list of series titlespoint_titles
- A list of point titles (categories)style
- Chart style numbervary_colors
- Boolean indicating whether to vary colors by pointview_3d
- 3D view options (rotation, perspective)legend
- Legend options (position, overlay)axes
- Axes options (titles, formatting)data_labels
- Data label optionschart_specific
- Chart-specific options
Returns
:ok
on success{:error, reason}
on failure
Sets 3D view properties for a chart.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetchart_index
- The index of the chart (0-based)rot_x
- X-axis rotation (degrees)rot_y
- Y-axis rotation (degrees)perspective
- Perspective (0-100)height_percent
- Height as percentage of width
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ChartFunctions.set_chart_3d_view(spreadsheet, "Sheet1", 0, 30, 20, 30, 100)
Sets axis titles for a chart.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetchart_index
- The index of the chart (0-based)category_axis_title
- The title for the category (X) axisvalue_axis_title
- The title for the value (Y) axis
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ChartFunctions.set_chart_axis_titles(spreadsheet, "Sheet1", 0, "Month", "Sales (USD)")
Sets data labels for a chart.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetchart_index
- The index of the chart (0-based)show_values
- Boolean indicating whether to show valuesshow_percent
- Boolean indicating whether to show percentagesshow_category_name
- Boolean indicating whether to show category namesshow_series_name
- Boolean indicating whether to show series namesposition
- The position of the data labels (e.g., "outside_end", "center", "inside_end")
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ChartFunctions.set_chart_data_labels(
spreadsheet,
"Sheet1",
0,
true,
false,
true,
false,
"outside_end"
)
Sets the legend position for a chart.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetchart_index
- The index of the chart (0-based)position
- The position of the legend (e.g., "right", "left", "top", "bottom", "top_right")overlay
- Boolean indicating whether the legend should overlay the chart
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ChartFunctions.set_chart_legend_position(spreadsheet, "Sheet1", 0, "right", false)
Sets the chart style.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetchart_index
- The index of the chart (0-based)style
- The style number (1-48)
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ChartFunctions.set_chart_style(spreadsheet, "Sheet1", 0, 5)