Class: Xlsxrb::ChartBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/xlsxrb/chart_builder.rb,
sig/generated/xlsxrb/chart_builder.rbs

Overview

Builder for block-style chart definitions.

Examples:

Create a chart definition

builder = ChartBuilder.new
builder.type(:bar)
builder.title("Quarterly Sales")
builder.series do |s|
  s.name("2026")
  s.categories("Sheet1!$A$2:$A$5")
  s.values("Sheet1!$B$2:$B$5")
end

Defined Under Namespace

Classes: SeriesBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHash{Symbol => Object}

: () -> void



22
23
24
# File 'lib/xlsxrb/chart_builder.rb', line 22

def initialize
  @options = {}
end

Instance Attribute Details

#optionsHash{Symbol => Object} (readonly)

: Hash[Symbol, untyped]

Returns:

  • (Hash{Symbol => Object})


28
29
30
# File 'lib/xlsxrb/chart_builder.rb', line 28

def options
  @options
end

Instance Method Details

#category_axis(*args, **kwargs) ⇒ Object

Configures the category axis properties for this chart.

: (*(Hash[Symbol, String | Integer | bool | nil] | String) args, **String | Integer | bool | nil kwargs) -> (Hash[Symbol, String | Integer | bool | nil] | String)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (Object)


172
173
174
# File 'lib/xlsxrb/chart_builder.rb', line 172

def category_axis(*args, **kwargs)
  @options[:category_axis] = kwargs.empty? ? args.first : kwargs
end

#chart_space(*args, **kwargs) ⇒ Object

Configures the chart_space property for this chart.

: (*(Hash[Symbol, String | Integer | bool | nil] | String) args, **String | Integer | bool | nil kwargs) -> (Hash[Symbol, String | Integer | bool | nil] | String)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (Object)

    The configured chart_space property.



106
107
108
# File 'lib/xlsxrb/chart_builder.rb', line 106

def chart_space(*args, **kwargs)
  @options[:chart_space] = kwargs.empty? ? args.first : kwargs
end

#data_labels(*args, **kwargs) ⇒ Object

Configures data labels for this chart.

: (*(Hash[Symbol, String | Integer | bool | nil] | String) args, **String | Integer | bool | nil kwargs) -> (Hash[Symbol, String | Integer | bool | nil] | String)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (Object)

    The configured data_labels property.



128
129
130
# File 'lib/xlsxrb/chart_builder.rb', line 128

def data_labels(*args, **kwargs)
  @options[:data_labels] = kwargs.empty? ? args.first : kwargs
end

#display_blanks_as(*args, **kwargs) ⇒ String

Configures how blank cells are displayed in the chart.

: (*(String) args, **String | Integer | bool | nil kwargs) -> String

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (String)


150
151
152
# File 'lib/xlsxrb/chart_builder.rb', line 150

def display_blanks_as(*args, **kwargs)
  @options[:display_blanks_as] = kwargs.empty? ? args.first : kwargs
end

#legend(*args, **kwargs) ⇒ Object

Configures the legend property for this chart.

: (*(Hash[Symbol, String | Integer | bool | nil] | String) args, **String | Integer | bool | nil kwargs) -> (Hash[Symbol, String | Integer | bool | nil] | String)

Parameters:

  • args (Array)

    Positional arguments (e.g. position string).

  • kwargs (Hash)

    Keyword arguments for legend styling/layout.

Returns:

  • (Object)

    The configured legend property.



84
85
86
# File 'lib/xlsxrb/chart_builder.rb', line 84

def legend(*args, **kwargs)
  @options[:legend] = kwargs.empty? ? args.first : kwargs
end

#plot_area(*args, **kwargs) ⇒ Object

Configures the plot_area property for this chart.

: (*(Hash[Symbol, String | Integer | bool | nil] | String) args, **String | Integer | bool | nil kwargs) -> (Hash[Symbol, String | Integer | bool | nil] | String)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments for plot area configuration.

Returns:

  • (Object)

    The configured plot_area property.



95
96
97
# File 'lib/xlsxrb/chart_builder.rb', line 95

def plot_area(*args, **kwargs)
  @options[:plot_area] = kwargs.empty? ? args.first : kwargs
end

#plot_visible_only(*args, **kwargs) ⇒ Boolean, String

Configures whether to plot visible cells only.

: (*(bool | String) args, **String | Integer | bool | nil kwargs) -> (bool | String)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (Boolean, String)


139
140
141
# File 'lib/xlsxrb/chart_builder.rb', line 139

def plot_visible_only(*args, **kwargs)
  @options[:plot_visible_only] = kwargs.empty? ? args.first : kwargs
end

#series(value) ⇒ Array<Hash{Symbol => Object}> #series {|series_builder| ... } ⇒ Array<Hash{Symbol => Object}>

This method returns an undefined value.

Adds a data series to the chart.

: (?Hash[Symbol, untyped]? value) ?{ (SeriesBuilder) -> void } -> Array[Hash[Symbol, untyped]]

Overloads:

  • #series(value) ⇒ Array<Hash{Symbol => Object}>

    Adds a pre-built series options hash.

    Parameters:

    • value (Hash{Symbol => Object})

      Series options hash.

    Returns:

    • (Array<Hash{Symbol => Object}>)
  • #series {|series_builder| ... } ⇒ Array<Hash{Symbol => Object}>

    Configures a series using a block.

    Yields:

    • (series_builder)

    Yield Parameters:

    Returns:

    • (Array<Hash{Symbol => Object}>)

Parameters:

  • value (Hash[Symbol, untyped], nil) (defaults to: nil)


65
66
67
68
69
70
71
72
73
74
75
# File 'lib/xlsxrb/chart_builder.rb', line 65

def series(value = nil)
  @options[:series] ||= []
  if block_given?
    sb = SeriesBuilder.new
    yield sb
    @options[:series] << sb.options
  elsif value
    @options[:series] << value
  end
  @options[:series]
end

#show_legend_key(*args, **kwargs) ⇒ Boolean, String

Configures whether to show the legend key in data labels.

: (*(bool | String) args, **String | Integer | bool | nil kwargs) -> (bool | String)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (Boolean, String)


194
195
196
# File 'lib/xlsxrb/chart_builder.rb', line 194

def show_legend_key(*args, **kwargs)
  @options[:show_legend_key] = kwargs.empty? ? args.first : kwargs
end

#style(*args, **kwargs) ⇒ Object

Configures the style index/id for this chart.

: (*(Hash[Symbol, String | Integer | bool | nil] | String | Integer) args, **String | Integer | bool | nil kwargs) -> (Hash[Symbol, String | Integer | bool | nil] | String | Integer)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (Object)

    The configured style property.



117
118
119
# File 'lib/xlsxrb/chart_builder.rb', line 117

def style(*args, **kwargs)
  @options[:style] = kwargs.empty? ? args.first : kwargs
end

#title(value) ⇒ String, ...

Sets the chart title.

: (String | Hash[Symbol, untyped] | nil value) -> (String | Hash[Symbol, untyped] | nil)

Parameters:

  • value (String, Hash, nil)

    Chart title text or options hash.

Returns:

  • (String, Hash, nil)


46
47
48
# File 'lib/xlsxrb/chart_builder.rb', line 46

def title(value)
  @options[:title] = value
end

#type(value) ⇒ Symbol, String

Sets the chart type (e.g. :line, :bar, :pie, :area, :radar, :scatter).

: (Symbol | String value) -> (Symbol | String)

Parameters:

  • value (Symbol, String)

    Chart type.

Returns:

  • (Symbol, String)


36
37
38
# File 'lib/xlsxrb/chart_builder.rb', line 36

def type(value)
  @options[:type] = value
end

#value_axis(*args, **kwargs) ⇒ Object

Configures the value axis properties for this chart.

: (*(Hash[Symbol, String | Integer | bool | nil] | String) args, **String | Integer | bool | nil kwargs) -> (Hash[Symbol, String | Integer | bool | nil] | String)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (Object)


183
184
185
# File 'lib/xlsxrb/chart_builder.rb', line 183

def value_axis(*args, **kwargs)
  @options[:value_axis] = kwargs.empty? ? args.first : kwargs
end

#view3d(*args, **kwargs) ⇒ Object

Configures 3D view properties for 3D charts.

: (*(Hash[Symbol, String | Integer | bool | nil] | String) args, **String | Integer | bool | nil kwargs) -> (Hash[Symbol, String | Integer | bool | nil] | String)

Parameters:

  • args (Array)

    Positional arguments.

  • kwargs (Hash)

    Keyword arguments.

Returns:

  • (Object)


161
162
163
# File 'lib/xlsxrb/chart_builder.rb', line 161

def view3d(*args, **kwargs)
  @options[:view3d] = kwargs.empty? ? args.first : kwargs
end