Module: Writexlsx::Chart::Settings

Included in:
Writexlsx::Chart
Defined in:
lib/write_xlsx/chart/settings.rb

Instance Method Summary collapse

Instance Method Details

#add_series(params) ⇒ Object

Add a series and it’s properties to a chart.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/write_xlsx/chart/settings.rb', line 16

def add_series(params)
  # Check that the required input has been specified.
  raise "Must specify ':values' in add_series" unless params.has_key?(:values)

  raise "Must specify ':categories' in add_series for this chart type" if @requires_category != 0 && !params.has_key?(:categories)

  raise "The maximum number of series that can be added to an Excel Chart is 255." if @series.size == 255

  @series << Series.new(self, params)

  # Set the secondary axis properties.
  x2_axis = params[:x2_axis]
  y2_axis = params[:y2_axis]

  # Store secondary status for combined charts.
  @is_secondary = true if ptrue?(x2_axis) || ptrue?(y2_axis)

  # Set the gap and overlap for Bar/Column charts.
  if params[:gap]
    if ptrue?(y2_axis)
      @series_gap_2 = params[:gap]
    else
      @series_gap_1 = params[:gap]
    end
  end

  # Set the overlap for Bar/Column charts.
  if params[:overlap]
    if ptrue?(y2_axis)
      @series_overlap_2 = params[:overlap]
    else
      @series_overlap_1 = params[:overlap]
    end
  end
end

#combine(chart) ⇒ Object

Add another chart to create a combined chart.



207
208
209
# File 'lib/write_xlsx/chart/settings.rb', line 207

def combine(chart)
  @combined = chart
end

#set_chartarea(params) ⇒ Object

Set the properties of the chart chartarea.



115
116
117
118
# File 'lib/write_xlsx/chart/settings.rb', line 115

def set_chartarea(params)
  # Convert the user defined properties to internal properties.
  @chartarea = ChartArea.new(params)
end

#set_drop_lines(params = {}) ⇒ Object

Set properties for the chart drop lines.



193
194
195
# File 'lib/write_xlsx/chart/settings.rb', line 193

def set_drop_lines(params = {})
  @drop_lines = Chartline.new(params)
end

#set_embedded_config_dataObject

Setup the default configuration data for an embedded chart.



214
215
216
# File 'lib/write_xlsx/chart/settings.rb', line 214

def set_embedded_config_data
  @embedded = true
end

#set_high_low_lines(params = {}) ⇒ Object

Set properties for the chart high-low lines.



200
201
202
# File 'lib/write_xlsx/chart/settings.rb', line 200

def set_high_low_lines(params = {})
  @hi_low_lines = Chartline.new(params)
end

#set_legend(params) ⇒ Object

Set the properties of the chart legend.



99
100
101
102
# File 'lib/write_xlsx/chart/settings.rb', line 99

def set_legend(params)
  # Convert the user default properties to internal properties.
  legend_properties(params)
end

#set_plotarea(params) ⇒ Object

Set the properties of the chart plotarea.



107
108
109
110
# File 'lib/write_xlsx/chart/settings.rb', line 107

def set_plotarea(params)
  # Convert the user defined properties to internal properties.
  @plotarea = ChartArea.new(params)
end

#set_size(params = {}) ⇒ Object Also known as: size

Set dimensions for scale for the chart.



149
150
151
152
153
154
155
156
# File 'lib/write_xlsx/chart/settings.rb', line 149

def set_size(params = {})
  @width    = params[:width]    if params[:width]
  @height   = params[:height]   if params[:height]
  @x_scale  = params[:x_scale]  if params[:x_scale]
  @y_scale  = params[:y_scale]  if params[:y_scale]
  @x_offset = params[:x_offset] if params[:x_offset]
  @y_offset = params[:y_offset] if params[:y_offset]
end

#set_style(style_id = 2) ⇒ Object

Set on of the 42 built-in Excel chart styles. The default style is 2.



123
124
125
126
# File 'lib/write_xlsx/chart/settings.rb', line 123

def set_style(style_id = 2)
  style_id = 2 if style_id < 1 || style_id > 48
  @style_id = style_id
end

#set_table(params = {}) ⇒ Object

The set_table method adds a data table below the horizontal axis with the data used to plot the chart.



165
166
167
168
# File 'lib/write_xlsx/chart/settings.rb', line 165

def set_table(params = {})
  @table = Table.new(params)
  @table.palette = @palette
end

#set_title(params) ⇒ Object

Set the properties of the chart title.



90
91
92
93
94
# File 'lib/write_xlsx/chart/settings.rb', line 90

def set_title(params)
  @title ||= Caption.new(self)
  @title.apply_text_options(params)
  @title.apply_format_options(params)
end

#set_up_down_bars(params = {}) ⇒ Object

Set properties for the chart up-down bars.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/write_xlsx/chart/settings.rb', line 173

def set_up_down_bars(params = {})
  # Map border to line.
  %i[up down].each do |up_down|
    if params[up_down]
      params[up_down][:line] = params[up_down][:border] if params[up_down][:border]
    else
      params[up_down] = {}
    end
  end

  # Set the up and down bar properties.
  @up_down_bars = {
    _up:   Chartline.new(params[:up]),
    _down: Chartline.new(params[:down])
  }
end

#set_x2_axis(params = {}) ⇒ Object

Set the properties of the secondary X-axis.



74
75
76
77
# File 'lib/write_xlsx/chart/settings.rb', line 74

def set_x2_axis(params = {})
  @date_category = true if ptrue?(params[:date_axis])
  @x2_axis.apply_options(params)
end

#set_x_axis(params = {}) ⇒ Object

Set the properties of the x-axis.



55
56
57
58
# File 'lib/write_xlsx/chart/settings.rb', line 55

def set_x_axis(params = {})
  @date_category = true if ptrue?(params[:date_axis])
  @x_axis.apply_options(params)
end

#set_y2_axis(params = {}) ⇒ Object

Set the properties of the secondary Y-axis.



82
83
84
85
# File 'lib/write_xlsx/chart/settings.rb', line 82

def set_y2_axis(params = {})
  @date_category = true if ptrue?(params[:date_axis])
  @y2_axis.apply_options(params)
end

#set_y_axis(params = {}) ⇒ Object

Set the properties of the Y-axis.

The set_y_axis() method is used to set properties of the Y axis. The properties that can be set are the same as for set_x_axis,



66
67
68
69
# File 'lib/write_xlsx/chart/settings.rb', line 66

def set_y_axis(params = {})
  @date_category = true if ptrue?(params[:date_axis])
  @y_axis.apply_options(params)
end

#show_blanks_as(option) ⇒ Object

Set the option for displaying blank data in a chart. The default is ‘gap’.



131
132
133
134
135
136
137
# File 'lib/write_xlsx/chart/settings.rb', line 131

def show_blanks_as(option)
  return unless option

  raise "Unknown show_blanks_as() option '#{option}'\n" unless %i[gap zero span].include?(option.to_sym)

  @show_blanks = option
end

#show_hidden_dataObject

Display data in hidden rows or columns on the chart.



142
143
144
# File 'lib/write_xlsx/chart/settings.rb', line 142

def show_hidden_data
  @show_hidden_data = true
end

#show_na_as_empty_cellObject

Set the option for displaying #N/A as an empty cell in a chart.



221
222
223
# File 'lib/write_xlsx/chart/settings.rb', line 221

def show_na_as_empty_cell
  @show_na_as_empty = true
end