UmyaSpreadsheet.ChartFunctions (umya_spreadsheet_ex v0.7.0)

View Source

Functions for creating and manipulating charts in a spreadsheet.

Summary

Functions

add_chart(spreadsheet, sheet_name, chart_type, from_cell, to_cell, title, data_series, series_titles, point_titles)

Adds a chart to a spreadsheet.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • chart_type - The type of chart (e.g., "bar", "line", "pie")
  • from_cell - The top-left cell of the chart position
  • to_cell - The bottom-right cell of the chart position
  • title - The title of the chart
  • data_series - A list of data series ranges
  • series_titles - A list of series titles
  • point_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"]
)

add_chart_with_options(spreadsheet, sheet_name, chart_type, from_cell, to_cell, title, data_series, series_titles, point_titles, style, vary_colors, view_3d, legend, axes, data_labels)

Adds a chart to a spreadsheet with advanced options.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • chart_type - The type of chart (e.g., "bar", "line", "pie")
  • from_cell - The top-left cell of the chart position
  • to_cell - The bottom-right cell of the chart position
  • title - The title of the chart
  • data_series - A list of data series ranges
  • series_titles - A list of series titles
  • point_titles - A list of point titles (categories)
  • style - Chart style number
  • vary_colors - Boolean indicating whether to vary colors by point
  • view_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"}
)

add_chart_with_options(spreadsheet, sheet_name, chart_type, from_cell, to_cell, title, data_series, series_titles, point_titles, style, vary_colors, view_3d, legend, axes, data_labels, chart_specific)

Adds a chart to a spreadsheet with advanced options, including chart-specific options.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • chart_type - The type of chart (e.g., "bar", "line", "pie")
  • from_cell - The top-left cell of the chart position
  • to_cell - The bottom-right cell of the chart position
  • title - The title of the chart
  • data_series - A list of data series ranges
  • series_titles - A list of series titles
  • point_titles - A list of point titles (categories)
  • style - Chart style number
  • vary_colors - Boolean indicating whether to vary colors by point
  • view_3d - 3D view options (rotation, perspective)
  • legend - Legend options (position, overlay)
  • axes - Axes options (titles, formatting)
  • data_labels - Data label options
  • chart_specific - Chart-specific options

Returns

  • :ok on success
  • {:error, reason} on failure

set_chart_3d_view(spreadsheet, sheet_name, chart_index, rot_x, rot_y, perspective, height_percent)

Sets 3D view properties for a chart.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • chart_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)

set_chart_axis_titles(spreadsheet, sheet_name, chart_index, category_axis_title, value_axis_title)

Sets axis titles for a chart.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • chart_index - The index of the chart (0-based)
  • category_axis_title - The title for the category (X) axis
  • value_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)")

set_chart_data_labels(spreadsheet, sheet_name, chart_index, show_values, show_percent, show_category_name, show_series_name, position)

Sets data labels for a chart.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • chart_index - The index of the chart (0-based)
  • show_values - Boolean indicating whether to show values
  • show_percent - Boolean indicating whether to show percentages
  • show_category_name - Boolean indicating whether to show category names
  • show_series_name - Boolean indicating whether to show series names
  • position - 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"
)

set_chart_legend_position(spreadsheet, sheet_name, chart_index, position, overlay)

Sets the legend position for a chart.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • chart_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)

set_chart_style(spreadsheet, sheet_name, chart_index, style)

Sets the chart style.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • chart_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)