Class: Writeexcel::Chart

Inherits:
Worksheet show all
Defined in:
lib/writeexcel/chart.rb,
lib/writeexcel/charts/bar.rb,
lib/writeexcel/charts/pie.rb,
lib/writeexcel/charts/area.rb,
lib/writeexcel/charts/line.rb,
lib/writeexcel/charts/stock.rb,
lib/writeexcel/charts/column.rb,
lib/writeexcel/charts/scatter.rb

Direct Known Subclasses

Area, Bar, Column, Line, Pie, Scatter, Stock, External

Defined Under Namespace

Classes: Area, Bar, Column, Line, Pie, Scatter, Stock

Constant Summary collapse

NonAscii =
/[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/

Constants inherited from Worksheet

Worksheet::Buffer, Worksheet::ColMax, Worksheet::RowMax, Worksheet::StrMax

Constants inherited from BIFFWriter

BIFFWriter::BIFF_Version, BIFFWriter::BigEndian

Instance Attribute Summary

Attributes inherited from BIFFWriter

#byte_order, #data, #datasize

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Worksheet

#activate, #active=, #add_write_handler, #autofilter, #center_horizontally, #center_vertically, #cleanup, #comment_params, #convert_date_time, #data_validation, #date_1904=, #encoding, #extract_filter_tokens, #filter_area, #filter_column, #filter_count, #fit_to_pages, #freeze_panes, #hidden, #hidden=, #hide, #hide_gridlines, #hide_zero, #image_mso_size, #image_mso_size=, #images_array, #index, #index=, #insert_chart, #insert_image, #keep_leading_zeros, #merge_cells, #merge_range, #name, #num_images, #num_images=, #object_ids=, #offset, #offset=, #outline_settings, #pack_dv_formula, #pack_dv_string, #parse_filter_expression, #position_object, #prepare_charts, #prepare_comments, #prepare_images, #print_across, #print_area, #print_colmax, #print_colmin, #print_row_col_headers, #print_rowmax, #print_rowmin, #protect, #repeat_columns, #repeat_formula, #repeat_rows, #right_to_left, #select, #selected, #selected=, #set_column, #set_comments_author, #set_first_row_column, #set_first_sheet, #set_footer, #set_h_pagebreaks, #set_header, #set_landscape, #set_margin_bottom, #set_margin_left, #set_margin_right, #set_margin_top, #set_margins, #set_margins_LR, #set_margins_TB, #set_page_view, #set_paper, #set_portrait, #set_print_scale, #set_row, #set_selection, #set_start_page, #set_tab_color, #set_v_pagebreaks, #set_zoom, #sheet_type, #show_comments, #split_panes, #store_autofilter, #store_colinfo, #store_dimensions, #store_dval, #store_filtermode, #store_formula, #store_mso_client_anchor, #store_mso_client_data, #store_mso_client_text_box, #store_mso_dg, #store_mso_dg_container, #store_mso_drawing_text_box, #store_mso_opt_chart, #store_mso_opt_comment, #store_mso_opt_filter, #store_mso_opt_image, #store_mso_sp, #store_mso_sp_container, #store_mso_spgr, #store_mso_spgr_container, #store_note, #store_obj_chart, #store_obj_comment, #store_obj_filter, #store_obj_image, #store_selection, #store_txo, #store_txo_continue_1, #store_txo_continue_2, #title_colmax, #title_colmin, #title_rowmax, #title_rowmin, #write, #write_blank, #write_col, #write_comment, #write_date_time, #write_formula, #write_number, #write_row, #write_string, #write_url, #write_url_range, #write_utf16be_string, #write_utf16le_string

Methods inherited from BIFFWriter

#add_continue, #add_mso_generic, #append, #cleanup, #clear_data_for_test, #get_data, #not_using_tmpfile, #print_caller_info, #set_byte_order, #store_bof, #store_eof

Methods included from CallerInfo

#caller_info

Methods inherited from WriteFile

#append

Constructor Details

#initialize(*args) ⇒ Chart

:call-seq:

new(filename, name, index, encoding, activesheet, firstsheet, external_bin = nil)

Default constructor for sub-classes.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/writeexcel/chart.rb', line 94

def initialize(*args)       #:nodoc:
  super

  @sheet_type  = 0x0200
  @orientation = 0x0
  @series      = []
  @embedded    = false

  @external_bin = false
  @x_axis_formula = nil
  @x_axis_name = nil
  @y_axis_formula = nil
  @y_axis_name = nil
  @title_name = nil
  @title_formula = nil
  @vary_data_color = 0
  set_default_properties
  set_default_config_data
end

Class Method Details

.factory(type, *args) ⇒ Object

factory()

Factory method for returning chart objects based on their class type.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/writeexcel/chart.rb', line 65

def self.factory(type, *args)       #:nodoc:
  klass =
  case type
  when 'Chart::Column'
    Chart::Column
  when 'Chart::Bar'
    Chart::Bar
  when 'Chart::Line'
    Chart::Line
  when 'Chart::Area'
    Chart::Area
  when 'Chart::Pie'
    Chart::Pie
  when 'Chart::Scatter'
    Chart::Scatter
  when 'Chart::Stock'
    Chart::Stock
  end

  klass.new(*args)
end

Instance Method Details

#add_series(params) ⇒ Object

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

In an Excel chart a “series” is a collection of information such as values, x-axis labels and the name that define which data is plotted. These settings are displayed when you select the Chart -> Source Data… menu option.

With a WriteExcel chart object the add_series() method is used to set the properties for a series:

chart.add_series(
  :categories    => '=Sheet1!$A$2:$A$10',
  :values        => '=Sheet1!$B$2:$B$10',
  :name          => 'Series name',
  :name_formula  => '=Sheet1!$B$1'
)

The properties that can be set are:

:values        (required)
:categories    (optional for most chart types)
:name          (optional)
:name_formula  (optional)

* :values

  This is the most important property of a series and must be set for
  every chart object. It links the chart with the worksheet data that
  it displays.

      chart.add_series(:values => '=Sheet1!$B$2:$B$10')

  Note the format that should be used for the formula. It is the same
  as is used in Excel. You must also add the worksheet that you are
  referring to before you link to it, via the workbook
  add_worksheet() method.

* :categories

  This sets the chart category labels. The category is more or less
  the same as the X-axis. In most chart types the categories property
  is optional and the chart will just assume a sequential series
  from 1 .. n.

      chart.add_series(
        :categories    => '=Sheet1!$A$2:$A$10',
        :values        => '=Sheet1!$B$2:$B$10'
      )

* :name

  Set the name for the series. The name is displayed in the chart
  legend and in the formula bar. The name property is optional and
  if it isn't supplied will default to Series 1 .. n.

      chart.add_series(
        ...
        :name          => 'Series name'
      )

* :name_formula

  Optional, can be used to link the name to a worksheet cell.
  See "Chart names and links".

      chart.add_series(
        ...
        :name          => 'Series name',
        :name_formula  => '=Sheet1!$B$1'
      )

You can add more than one series to a chart. The series numbering and order in the final chart is the same as the order in which that are added.

# Add the first series.
chart.add_series(
  :categories => '=Sheet1!$A$2:$A$7',
  :values     => '=Sheet1!$B$2:$B$7',
  :name       => 'Test data series 1'
)

# Add another series. Category is the same but values are different.
chart.add_series(
  :categories => '=Sheet1!$A$2:$A$7',
  :values     => '=Sheet1!$C$2:$C$7',
  :name       => 'Test data series 2'
)


203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/writeexcel/chart.rb', line 203

def add_series(params)
  raise "Must specify 'values' in add_series()" if params[:values].nil?

  # Parse the ranges to validate them and extract salient information.
  value_data    = parse_series_formula(params[:values])
  category_data = parse_series_formula(params[:categories])
  name_formula  = parse_series_formula(params[:name_formula])

  # Default category count to the same as the value count if not defined.
  category_data[1] = value_data[1] if category_data.size < 2

  # Add the parsed data to the user supplied data.
  params[:values]       = value_data
  params[:categories]   = category_data
  params[:name_formula] = name_formula

  # Encode the Series name.
  name, encoding = encode_utf16(params[:name], params[:name_encoding])

  params[:name]          = name
  params[:name_encoding] = encoding

  @series << params
end

#closeObject

_close(), overridden.

Create and store the Chart data structures.



515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/writeexcel/chart.rb', line 515

def close  # :nodoc:
  # Ignore any data that has been written so far since it is probably
  # from unwanted Worksheet method calls.
  @data = ''

  # TODO. Check for charts without a series?

  # Store the chart BOF.
  store_bof(0x0020)

  # Store the page header
  store_header

  # Store the page footer
  store_footer

  # Store the page horizontal centering
  store_hcenter

  # Store the page vertical centering
  store_vcenter

  # Store the left margin
  store_margin_left

  # Store the right margin
  store_margin_right

  # Store the top margin
  store_margin_top

  # Store the bottom margin
  store_margin_bottom

  # Store the page setup
  store_setup

  # Store the sheet password
  store_password

  # Start of Chart specific records.

  # Store the FBI font records.
  store_fbi(*@config[:font_numbers])
  store_fbi(*@config[:font_series])
  store_fbi(*@config[:font_title])
  store_fbi(*@config[:font_axes])

  # Ignore UNITS record.

  # Store the Chart sub-stream.
  store_chart_stream

  # Append the sheet dimensions
  store_dimensions

  # TODO add SINDEX and NUMBER records.

  store_window2 unless @embedded

  store_eof
end

#data=(val) ⇒ Object

:nodoc:



482
483
484
# File 'lib/writeexcel/chart.rb', line 482

def data=(val)  # :nodoc:
  @data = val
end

#embeddedObject

:nodoc:



486
487
488
# File 'lib/writeexcel/chart.rb', line 486

def embedded  # :nodoc:
  @embedded
end

#embedded=(val) ⇒ Object

:nodoc:



490
491
492
# File 'lib/writeexcel/chart.rb', line 490

def embedded=(val)  # :nodoc:
  @embedded = val
end

#encode_utf16(str, encoding = 0) ⇒ Object

_encode_utf16()

Convert UTF8 strings used in the chart to UTF16.



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/writeexcel/chart.rb', line 683

def encode_utf16(str, encoding = 0)  # :nodoc:
  # Exit if the $string isn't defined, i.e., hasn't been set by user.
  return [nil, nil] if str.nil?

  string = str.dup
  # Return if encoding is set, i.e., string has been manually encoded.
  #return ( undef, undef ) if $string == 1;

  ruby_19 { string = convert_to_ascii_if_ascii(string) }

  # Handle utf8 strings.
  ruby_18 do
    if string =~ NonAscii
      string = utf8_to_16be(string)
      encoding = 1
    end
  end
  ruby_19 do
    if string.encoding == Encoding::UTF_8
      string = utf8_to_16be(string)
      encoding = 1
    end
  end

  # Chart strings are limited to 255 characters.
  limit = encoding != 0 ? 255 * 2 : 255

  if string.bytesize >= limit
    # truncate the string and raise a warning.
    string = string[0, limit]
  end

  [string, encoding]
end

#get_color_indices(color) ⇒ Object

_get_color_indices()

Convert the user specified colour index or string to an colour index and RGB colour number.



725
726
727
728
729
730
731
732
733
734
735
# File 'lib/writeexcel/chart.rb', line 725

def get_color_indices(color)   # :nodoc:
  invalid = 0x7FFF   # return from Colors#get_color when color is invalid

  index = Colors.new.get_color(color)
  index = invalid if color.respond_to?(:coerce) && (color < 8 || color > 63)
  if index == invalid
    [nil, nil]
  else
    [index, get_color_rbg(index)]
  end
end

#get_color_rbg(index) ⇒ Object

_get_color_rbg()

Get the RedGreenBlue number for the colour index from the Workbook palette.



743
744
745
746
747
748
749
# File 'lib/writeexcel/chart.rb', line 743

def get_color_rbg(index)   # :nodoc:
  # Adjust colour index from 8-63 (user range) to 0-55 (Excel range).
  index -= 8

  red_green_blue = @palette[index]
  red_green_blue.pack('C*').unpack('V')[0]
end

#get_line_pattern(value) ⇒ Object

_get_line_pattern()

Get the Excel chart index for line pattern that corresponds to the user defined value.



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
# File 'lib/writeexcel/chart.rb', line 758

def get_line_pattern(value)   # :nodoc:
  value = value.downcase if value.respond_to?(:to_str)
  default = 0

  patterns = {
    0              => 5,
    1              => 0,
    2              => 1,
    3              => 2,
    4              => 3,
    5              => 4,
    6              => 7,
    7              => 6,
    8              => 8,
    'solid'        => 0,
    'dash'         => 1,
    'dot'          => 2,
    'dash-dot'     => 3,
    'dash-dot-dot' => 4,
    'none'         => 5,
    'dark-gray'    => 6,
    'medium-gray'  => 7,
    'light-gray'   => 8,
  }

  if patterns.has_key?(value)
    patterns[value]
  else
    default
  end
end

#get_line_weight(value) ⇒ Object

_get_line_weight()

Get the Excel chart index for line weight that corresponds to the user defined value.



797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/writeexcel/chart.rb', line 797

def get_line_weight(value)   # :nodoc:
  value = value.downcase if value.respond_to?(:to_str)
  default = 0

  weights = {
    1          => -1,
    2          => 0,
    3          => 1,
    4          => 2,
    'hairline' => -1,
    'narrow'   => 0,
    'medium'   => 1,
    'wide'     => 2,
  }

  if weights.has_key?(value)
    weights[value]
  else
    default
  end
end

#parse_series_formula(formula) ⇒ Object

_parse_series_formula()

Parse the formula used to define a series. We also extract some range information required for _store_series() and the SERIES record.



636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/writeexcel/chart.rb', line 636

def parse_series_formula(formula)  # :nodoc:
  encoding = 0
  length   = 0
  count    = 0
  tokens = []

  return [''] if formula.nil?

  # Strip the = sign at the beginning of the formula string
  formula = formula.sub(/^=/, '')

  # Parse the formula using the parser in Formula.pm
  parser = @parser

  # In order to raise formula errors from the point of view of the calling
  # program we use an eval block and re-raise the error from here.
  #
  tokens = parser.parse_formula(formula)

  # Force ranges to be a reference class.
  tokens.collect! { |t| t.gsub(/_ref3d/, '_ref3dR') }
  tokens.collect! { |t| t.gsub(/_range3d/, '_range3dR') }
  tokens.collect! { |t| t.gsub(/_name/, '_nameR') }

  # Parse the tokens into a formula string.
  formula = parser.parse_tokens(tokens)

  # Return formula for a single cell as used by title and series name.
  return formula if formula.ord == 0x3A

  # Extract the range from the parse formula.
  if formula.ord == 0x3B
      ptg, ext_ref, row_1, row_2, col_1, col_2 = formula.unpack('Cv5')

      # TODO. Remove high bit on relative references.
      count = row_2 - row_1 + 1
  end

  [formula, count]
end

#prepend(*args) ⇒ Object

_prepend(), overridden.

The parent Worksheet class needs to store some data in memory and some in temporary files for efficiency. The Chart* classes don’t need to do this since they are dealing with smaller amounts of data so we override _prepend() to turn it into an _append() method. This allows for a more natural method calling order.



504
505
506
507
# File 'lib/writeexcel/chart.rb', line 504

def prepend(*args)  # :nodoc:
  @using_tmpfile = false
  append(*args)
end

#set_chartarea(params = {}) ⇒ Object

set_chartarea()

Set the properties of the chart chartarea.



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/writeexcel/chart.rb', line 422

def set_chartarea(params = {})
  return if params.empty?

  area = @chartarea

  # Embedded automatic line weight has a different default value.
  area[:line_weight] = 0xFFFF if @embedded

  # Set the chart background colour.
  if params.has_key?(:color)
    index, rgb = get_color_indices(params[:color])
    if !index.nil?
      area[:fg_color_index] = index
      area[:fg_color_rgb]   = rgb
      area[:bg_color_index] = 0x08
      area[:bg_color_rgb]   = 0x000000
      area[:area_pattern]   = 1
      area[:area_options]   = 0x0000 if @embedded
      area[:visible]        = 1
    end
  end

  # Set the border line colour.
  if params.has_key?(:line_color)
    index, rgb = get_color_indices(params[:line_color])
    if !index.nil?
      area[:line_color_index] = index
      area[:line_color_rgb]   = rgb
      area[:line_pattern]     = 0x00
      area[:line_options]     = 0x0000
      area[:visible]          = 1
    end
  end

  # Set the border line pattern.
  if params.has_key?(:line_pattern)
    pattern = get_line_pattern(params[:line_pattern])
    area[:line_pattern]     = pattern
    area[:line_options]     = 0x0000
    area[:line_color_index] = 0x4F unless params.has_key?(:line_color)
    area[:visible]          = 1
  end

  # Set the border line weight.
  if params.has_key?(:line_weight)
      weight = get_line_weight(params[:line_weight])
      area[:line_weight]      = weight
      area[:line_options]     = 0x0000
      area[:line_pattern]     = 0x00 unless params.has_key?(:line_pattern)
      area[:line_color_index] = 0x4F unless params.has_key?(:line_color)
      area[:visible]          = 1
  end
end

#set_default_config_dataObject

_set_default_config_data()

Setup the default configuration data for a chart.



2118
2119
2120
# File 'lib/writeexcel/chart.rb', line 2118

def set_default_config_data   # :nodoc:
  @config = default_config_data
end

#set_default_propertiesObject

_set_default_properties()

Setup the default properties for a chart.



2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
# File 'lib/writeexcel/chart.rb', line 2074

def set_default_properties   # :nodoc:
  @legend = {
    :visible  => 1,
    :position => 0,
    :vertical => 0,
  }

  @chartarea = {
    :visible          => 0,
    :fg_color_index   => 0x4E,
    :fg_color_rgb     => 0xFFFFFF,
    :bg_color_index   => 0x4D,
    :bg_color_rgb     => 0x000000,
    :area_pattern     => 0x0000,
    :area_options     => 0x0000,
    :line_pattern     => 0x0005,
    :line_weight      => 0xFFFF,
    :line_color_index => 0x4D,
    :line_color_rgb   => 0x000000,
    :line_options     => 0x0008,
  }

  @plotarea = {
    :visible          => 1,
    :fg_color_index   => 0x16,
    :fg_color_rgb     => 0xC0C0C0,
    :bg_color_index   => 0x4F,
    :bg_color_rgb     => 0x000000,
    :area_pattern     => 0x0001,
    :area_options     => 0x0000,
    :line_pattern     => 0x0000,
    :line_weight      => 0x0000,
    :line_color_index => 0x17,
    :line_color_rgb   => 0x808080,
    :line_options     => 0x0000,
  }
end

#set_embedded_config_dataObject

_set_embedded_config_data()

Setup the default configuration data for an embedded chart.



2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
# File 'lib/writeexcel/chart.rb', line 2153

def set_embedded_config_data   # :nodoc:
  @embedded = true

  @chartarea = {
    :visible          => 1,
    :fg_color_index   => 0x4E,
    :fg_color_rgb     => 0xFFFFFF,
    :bg_color_index   => 0x4D,
    :bg_color_rgb     => 0x000000,
    :area_pattern     => 0x0001,
    :area_options     => 0x0001,
    :line_pattern     => 0x0000,
    :line_weight      => 0x0000,
    :line_color_index => 0x4D,
    :line_color_rgb   => 0x000000,
    :line_options     => 0x0009,
  }

  @config = default_config_data.merge({
      :axisparent      => [ 0, 0x01D8, 0x031D, 0x0D79, 0x07E9              ],
      :axisparent_pos  => [ 2, 2, 0x010C, 0x0292, 0x0E46, 0x09FD           ],
      :chart           => [ 0x0000, 0x0000, 0x01847FE8, 0x00F47FE8         ],
      :font_numbers    => [ 5, 10, 0x1DC4, 0x1284, 0x0000                  ],
      :font_series     => [ 6, 10, 0x1DC4, 0x1284, 0x0001                  ],
      :font_title      => [ 7, 12, 0x1DC4, 0x1284, 0x0000                  ],
      :font_axes       => [ 8, 10, 0x1DC4, 0x1284, 0x0001                  ],
      :legend          => [ 0x044E, 0x0E4A, 0x088D, 0x0123, 0x0, 0x1, 0xF  ],
      :legend_pos      => [ 5, 2, 0x044E, 0x0E4A, 0, 0                     ],
      :legend_text     => [ 0xFFFFFFD9, 0xFFFFFFC1, 0, 0, 0x00B1, 0x0000   ],
      :series_text     => [ 0xFFFFFFD9, 0xFFFFFFC1, 0, 0, 0x00B1, 0x1020   ],
      :title_text      => [ 0x060F, 0x004C, 0x038A, 0x016F, 0x0081, 0x1030 ],
      :x_axis_text     => [ 0x07EF, 0x0C8F, 0x153, 0x123, 0x81, 0x00       ],
      :y_axis_text     => [ 0x0057, 0x0564, 0xB5, 0x035D, 0x0281, 0x00, 90 ],
  })
end

#set_legend(params = {}) ⇒ Object

set_legend()

Set the properties of the chart legend.



355
356
357
358
359
360
361
# File 'lib/writeexcel/chart.rb', line 355

def set_legend(params = {})
  if params.has_key?(:position)
    if params[:position].downcase == 'none'
      legend[:visible] = 0
    end
  end
end

#set_plotarea(params = {}) ⇒ Object

set_plotarea()

Set the properties of the chart plotarea.



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/writeexcel/chart.rb', line 369

def set_plotarea(params = {})
  return if params.empty?

  area = @plotarea

  # Set the plotarea visibility.
  if params.has_key?(:visible)
    area[:visible] = params[:visible]
    return if area[:visible] == 0
  end

  # TODO. could move this out of if statement.
  area[:bg_color_index] = 0x08

  # Set the chart background colour.
  if params.has_key?(:color)
    index, rgb = get_color_indices(params[:color])
    if !index.nil?
      area[:fg_color_index] = index
      area[:fg_color_rgb]   = rgb
      area[:bg_color_index] = 0x08
      area[:bg_color_rgb]   = 0x000000
    end
  end

  # Set the border line colour.
  if params.has_key?(:line_color)
    index, rgb = get_color_indices(params[:line_color])
    if !index.nil?
      area[:line_color_index] = index
      area[:line_color_rgb]   = rgb
    end
  end

  # Set the border line pattern.
  if params.has_key?(:line_pattern)
      pattern = get_line_pattern(params[:line_pattern])
      area[:line_pattern] = pattern
  end

  # Set the border line weight.
  if params.has_key?(:line_weight)
      weight = get_line_weight(params[:line_weight])
      area[:line_weight] = weight
  end
end

#set_title(params) ⇒ Object

The set_title() method is used to set properties of the chart title.

chart.set_title(:name => 'Year End Results')

The properties that can be set are:

:name          (optional)
:name_formula  (optional)

* :name

  Set the name (title) for the chart. The name is displayed above the
  chart. This property is optional. The default is to have no chart
  title.

      chart.set_title(:name => 'Year End Results')

* :name_formula

  Optional, can be used to link the name to a worksheet cell.
  See "Chart names and links".

      chart.set_title(
        :name          => 'Year End Results',
        :name_formula  => '=Sheet1!$C$1'
      )


339
340
341
342
343
344
345
346
347
# File 'lib/writeexcel/chart.rb', line 339

def set_title(params)
  name, encoding = encode_utf16( params[:name], params[:name_encoding])

  formula = parse_series_formula(params[:name_formula])

  @title_name     = name
  @title_encoding = encoding
  @title_formula  = formula
end

#set_x_axis(params) ⇒ Object

Set the properties of the X-axis.

The set_x_axis() method is used to set properties of the X axis.

chart.set_x_axis(:name => 'Sample length (m)' )

The properties that can be set are:

:name          (optional)
:name_formula  (optional)

* :name

  Set the name (title or caption) for the axis. The name is displayed
  below the X axis. This property is optional. The default is to have
  no axis name.

      chart.set_x_axis( :name => 'Sample length (m)' )

* :name_formula

  Optional, can be used to link the name to a worksheet cell.
  See "Chart names and links".

      chart.set_x_axis(
        :name          => 'Sample length (m)',
        :name_formula  => '=Sheet1!$A$1'
      )

Additional axis properties such as range, divisions and ticks will be made available in later releases.



260
261
262
263
264
265
266
267
# File 'lib/writeexcel/chart.rb', line 260

def set_x_axis(params)
  name, encoding = encode_utf16(params[:name], params[:name_encoding])
  formula = parse_series_formula(params[:name_formula])

  @x_axis_name     = name
  @x_axis_encoding = encoding
  @x_axis_formula  = formula
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.

chart.set_y_axis(:name => 'Sample weight (kg)' )

The properties that can be set are:

:name          (optional)
:name_formula  (optional)

* :name

  Set the name (title or caption) for the axis. The name is displayed
  to the left of the Y axis. This property is optional. The default
  is to have no axis name.

      chart.set_y_axis(:name => 'Sample weight (kg)' )

* :name_formula

  Optional, can be used to link the name to a worksheet cell.
  See "Chart names and links".

      chart.set_y_axis(
        :name          => 'Sample weight (kg)',
        :name_formula  => '=Sheet1!$B$1'
      )

Additional axis properties such as range, divisions and ticks will be made available in later releases.



302
303
304
305
306
307
308
309
# File 'lib/writeexcel/chart.rb', line 302

def set_y_axis(params)
  name, encoding = encode_utf16(params[:name], params[:name_encoding])
  formula = parse_series_formula(params[:name_formula])

  @y_axis_name     = name
  @y_axis_encoding = encoding
  @y_axis_formula  = formula
end

#store_3dbarshapeObject

_store_3dbarshape()

Write the 3DBARSHAPE chart BIFF record.



1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
# File 'lib/writeexcel/chart.rb', line 1219

def store_3dbarshape   # :nodoc:
  record = 0x105F    # Record identifier.
  length = 0x0002    # Number of bytes to follow.
  riser  = 0x00      # Shape of base.
  taper  = 0x00      # Column taper type.

  header = [record, length].pack('vv')
  data   = [riser].pack('C')
  data  += [taper].pack('C')

  append(header, data)
end

#store_ai(id, type, formula, format_index = 0) ⇒ Object

_store_ai()

Write the AI chart BIFF record.



1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
# File 'lib/writeexcel/chart.rb', line 1238

def store_ai(id, type, formula, format_index = 0)   # :nodoc:
  formula = '' if formula == [""]

  record       = 0x1051     # Record identifier.
  length       = 0x0008     # Number of bytes to follow.
  # id                      # Link index.
  # type                    # Reference type.
  # formula                 # Pre-parsed formula.
  # format_index            # Num format index.
  grbit        = 0x0000     # Option flags.

  ruby_19 { formula = convert_to_ascii_if_ascii(formula) }

  formula_length  = formula.bytesize
  length += formula_length

  header = [record, length].pack('vv')
  data   = [id].pack('C')
  data  += [type].pack('C')
  data  += [grbit].pack('v')
  data  += [format_index].pack('v')
  data  += [formula_length].pack('v')
  if formula.respond_to?(:to_array)
    data +=
      ruby_18 { formula[0] } ||
      ruby_19 { formula[0].encode('BINARY') }
  else
    data +=
      ruby_18 { formula                  unless formula.nil? } ||
      ruby_19 { formula.encode('BINARY') unless formula.nil? }
  end

  append(header, data)
end

#store_areaformat(rgbFore, rgbBack, pattern, grbit, indexFore, indexBack) ⇒ Object

_store_areaformat()

Write the AREAFORMAT chart BIFF record. Contains the patterns and colours of a chart area.



1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
# File 'lib/writeexcel/chart.rb', line 1280

def store_areaformat(rgbFore, rgbBack, pattern, grbit, indexFore, indexBack)  # :nodoc:
  record    = 0x100A     # Record identifier.
  length    = 0x0010     # Number of bytes to follow.
  # rgbFore              # Foreground RGB colour.
  # rgbBack              # Background RGB colour.
  # pattern              # Pattern.
  # grbit                # Option flags.
  # indexFore            # Index to Foreground colour.
  # indexBack            # Index to Background colour.

  header = [record, length].pack('vv')
  data  = [rgbFore].pack('V')
  data += [rgbBack].pack('V')
  data += [pattern].pack('v')
  data += [grbit].pack('v')
  data += [indexFore].pack('v')
  data += [indexBack].pack('v')

  append(header, data)
end

#store_axcextObject

_store_axcext()

Write the AXCEXT chart BIFF record.



1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
# File 'lib/writeexcel/chart.rb', line 1307

def store_axcext  # :nodoc:
  record       = 0x1062     # Record identifier.
  length       = 0x0012     # Number of bytes to follow.
  catMin       = 0x0000     # Minimum category on axis.
  catMax       = 0x0000     # Maximum category on axis.
  catMajor     = 0x0001     # Value of major unit.
  unitMajor    = 0x0000     # Units of major unit.
  catMinor     = 0x0001     # Value of minor unit.
  unitMinor    = 0x0000     # Units of minor unit.
  unitBase     = 0x0000     # Base unit of axis.
  catCrossDate = 0x0000     # Crossing point.
  grbit        = 0x00EF     # Option flags.

  store_simple(record, length, catMin, catMax, catMajor, unitMajor,
               catMinor, unitMinor, unitBase, catCrossDate, grbit)
end

#store_axesused(num_axes) ⇒ Object

_store_axesused()

Write the AXESUSED chart BIFF record.



1330
1331
1332
1333
1334
1335
1336
# File 'lib/writeexcel/chart.rb', line 1330

def store_axesused(num_axes)   # :nodoc:
  record   = 0x1046     # Record identifier.
  length   = 0x0002     # Number of bytes to follow.
  # num_axes            # Number of axes used.

  store_simple(record, length, num_axes)
end

#store_axis(type) ⇒ Object

_store_axis()

Write the AXIS chart BIFF record to define the axis type.



1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
# File 'lib/writeexcel/chart.rb', line 1344

def store_axis(type)   # :nodoc:
  record    = 0x101D         # Record identifier.
  length    = 0x0012         # Number of bytes to follow.
  # type                     # Axis type.
  reserved1 = 0x00000000     # Reserved.
  reserved2 = 0x00000000     # Reserved.
  reserved3 = 0x00000000     # Reserved.
  reserved4 = 0x00000000     # Reserved.

  header = [record, length].pack('vv')
  data  = [type].pack('v')
  data += [reserved1].pack('V')
  data += [reserved2].pack('V')
  data += [reserved3].pack('V')
  data += [reserved4].pack('V')

  append(header, data)
end

#store_axis_category_streamObject

_store_axis_category_stream()

Write the AXIS chart substream for the chart category.



1070
1071
1072
1073
1074
1075
1076
1077
1078
# File 'lib/writeexcel/chart.rb', line 1070

def store_axis_category_stream   # :nodoc:
  store_axis(0)

  store_begin
  store_catserrange
  store_axcext
  store_tick
  store_end
end

#store_axis_values_streamObject

_store_axis_values_stream()

Write the AXIS chart substream for the chart values.



1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
# File 'lib/writeexcel/chart.rb', line 1086

def store_axis_values_stream   # :nodoc:
  store_axis(1)

  store_begin
  store_valuerange
  store_tick
  store_axislineformat
  store_lineformat(0x00000000, 0x0000, 0xFFFF, 0x0009, 0x004D)
  store_end
end

#store_axislineformatObject

_store_axislineformat()

Write the AXISLINEFORMAT chart BIFF record.



1369
1370
1371
1372
1373
1374
1375
# File 'lib/writeexcel/chart.rb', line 1369

def store_axislineformat   # :nodoc:
  record      = 0x1021     # Record identifier.
  length      = 0x0002     # Number of bytes to follow.
  line_format = 0x0001     # Axis line format.

  store_simple(record, length, line_format)
end

#store_axisparent(iax, x, y, dx, dy) ⇒ Object

_store_axisparent()

Write the AXISPARENT chart BIFF record.



1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
# File 'lib/writeexcel/chart.rb', line 1383

def store_axisparent(iax, x, y, dx, dy)  # :nodoc:
  record = 0x1041         # Record identifier.
  length = 0x0012         # Number of bytes to follow.
  # iax                   # Axis index.
  # x                     # X-coord.
  # y                     # Y-coord.
  # dx                    # Length of x axis.
  # dy                    # Length of y axis.

  header = [record, length].pack('vv')
  data   = [iax].pack('v')
  data  += [x].pack('V')
  data  += [y].pack('V')
  data  += [dx].pack('V')
  data  += [dy].pack('V')

  append(header, data)
end

#store_axisparent_streamObject

_store_axisparent_stream()

Write the AXISPARENT chart substream.



1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
# File 'lib/writeexcel/chart.rb', line 1040

def store_axisparent_stream   # :nodoc:
  store_axisparent(*@config[:axisparent])

  store_begin
  store_pos(*@config[:axisparent_pos])
  store_axis_category_stream
  store_axis_values_stream

  if !@x_axis_name.nil? || !@x_axis_formula.nil?
    store_x_axis_text_stream
  end

  if !@y_axis_name.nil? || !@y_axis_formula.nil?
    store_y_axis_text_stream();
  end

  if @plotarea[:visible] != 0
    store_plotarea
    store_plotarea_frame_stream
  end
  store_chartformat_stream
  store_end
end

#store_beginObject

_store_begin()

Write the BEGIN chart BIFF record to indicate the start of a sub stream.



1408
1409
1410
1411
1412
1413
# File 'lib/writeexcel/chart.rb', line 1408

def store_begin   # :nodoc:
  record = 0x1033     # Record identifier.
  length = 0x0000     # Number of bytes to follow.

  store_simple(record, length)
end

#store_catserrangeObject

_store_catserrange()

Write the CATSERRANGE chart BIFF record.



1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
# File 'lib/writeexcel/chart.rb', line 1421

def store_catserrange   # :nodoc:
  record   = 0x1020     # Record identifier.
  length   = 0x0008     # Number of bytes to follow.
  catCross = 0x0001     # Value/category crossing.
  catLabel = 0x0001     # Frequency of labels.
  catMark  = 0x0001     # Frequency of ticks.
  grbit    = 0x0001     # Option flags.

  store_simple(record, length, catCross, catLabel, catMark, grbit)
end

#store_chart(x_pos, y_pos, dx, dy) ⇒ Object

_store_chart()

Write the CHART BIFF record. This indicates the start of the chart sub-stream and contains dimensions of the chart on the display. Units are in 1/72 inch and are 2 byte integer with 2 byte fraction.



1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
# File 'lib/writeexcel/chart.rb', line 1440

def store_chart(x_pos, y_pos, dx, dy)   # :nodoc:
  record   = 0x1002     # Record identifier.
  length   = 0x0010     # Number of bytes to follow.
  # x_pos               # X pos of top left corner.
  # y_pos               # Y pos of top left corner.
  # dx                  # X size.
  # dy                  # Y size.

  header = [record, length].pack('vv')
  data   = [x_pos].pack('V')
  data  += [y_pos].pack('V')
  data  += [dx].pack('V')
  data  += [dy].pack('V')

  append(header, data)
end

#store_chart_streamObject

_store_chart_stream()

Store the CHART record and it’s substreams.



825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
# File 'lib/writeexcel/chart.rb', line 825

def store_chart_stream # :nodoc:
  store_chart(*@config[:chart])
  store_begin

  # Store the chart SCL record.
  store_plotgrowth

  if @chartarea[:visible] != 0
    store_chartarea_frame_stream
  end

  # Store SERIES stream for each series.
  index = 0
  @series.each do |series|
    store_series_stream(
        :index            => index,
        :value_formula    => series[:values][0],
        :value_count      => series[:values][1],
        :category_count   => series[:categories][1],
        :category_formula => series[:categories][0],
        :name             => series[:name],
        :name_encoding    => series[:name_encoding],
        :name_formula     => series[:name_formula]
      )
      index += 1
  end

  store_shtprops

  # Write the TEXT streams.
  (5..6).each do |font_index|
    store_defaulttext
    store_series_text_stream(font_index)
  end

  store_axesused(1)
  store_axisparent_stream

  if !@title_name.nil? || !@title_formula.nil?
    store_title_text_stream
  end

  store_end
end

#store_chart_typeObject

_store_chart_type()

This is an abstract method that is overridden by the sub-classes to define the chart types such as Column, Line, Pie, etc.



1177
1178
1179
# File 'lib/writeexcel/chart.rb', line 1177

def store_chart_type   # :nodoc:

end

#store_chartarea_frame_streamObject

_store_chartarea_frame_stream()

Write the FRAME chart substream for and embedded chart.



1113
1114
1115
# File 'lib/writeexcel/chart.rb', line 1113

def store_chartarea_frame_stream   # :nodoc:
  store_area_frame_stream_common(:chart)
end

#store_chartformat(grbit = 0) ⇒ Object

_store_chartformat()

Write the CHARTFORMAT chart BIFF record. The parent record for formatting of a chart group.



1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
# File 'lib/writeexcel/chart.rb', line 1464

def store_chartformat(grbit = 0)   # :nodoc:
  record    = 0x1014         # Record identifier.
  length    = 0x0014         # Number of bytes to follow.
  reserved1 = 0x00000000     # Reserved.
  reserved2 = 0x00000000     # Reserved.
  reserved3 = 0x00000000     # Reserved.
  reserved4 = 0x00000000     # Reserved.
  # grbit                    # Option flags.
  icrt      = 0x0000         # Drawing order.

  header = [record, length].pack('vv')
  data   = [reserved1].pack('V')
  data  += [reserved2].pack('V')
  data  += [reserved3].pack('V')
  data  += [reserved4].pack('V')
  data  += [grbit].pack('v')
  data  += [icrt].pack('v')

  append(header, data)
end

#store_chartformat_streamObject

_store_chartformat_stream()

Write the CHARTFORMAT chart substream.



1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
# File 'lib/writeexcel/chart.rb', line 1151

def store_chartformat_stream   # :nodoc:
  # The _vary_data_color is set by classes that need it, like Pie.
  store_chartformat(@vary_data_color)

  store_begin

  # Store the BIFF record that will define the chart type.
  store_chart_type

  # Note, the CHARTFORMATLINK record is only written by Excel.

  if @legend[:visible]
      store_legend_stream
  end

  store_marker_dataformat_stream
  store_end
end

#store_chartlineObject

_store_chartline()

Write the CHARTLINE chart BIFF record.



1491
1492
1493
1494
1495
1496
1497
# File 'lib/writeexcel/chart.rb', line 1491

def store_chartline   # :nodoc:
  record = 0x101C     # Record identifier.
  length = 0x0002     # Number of bytes to follow.
  type   = 0x0001     # Drop/hi-lo line type.

  store_simple(record, length, type)
end

#store_charttextObject

_store_charttext()

Write the TEXT chart BIFF record.



1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
# File 'lib/writeexcel/chart.rb', line 1505

def store_charttext   # :nodoc:
  record           = 0x1025         # Record identifier.
  length           = 0x0020         # Number of bytes to follow.
  horz_align       = 0x02           # Horizontal alignment.
  vert_align       = 0x02           # Vertical alignment.
  bg_mode          = 0x0001         # Background display.
  text_color_rgb   = 0x00000000     # Text RGB colour.
  text_x           = 0xFFFFFF46     # Text x-pos.
  text_y           = 0xFFFFFF06     # Text y-pos.
  text_dx          = 0x00000000     # Width.
  text_dy          = 0x00000000     # Height.
  grbit1           = 0x00B1         # Options
  text_color_index = 0x004D         # Auto Colour.
  grbit2           = 0x0000         # Data label placement.
  rotation         = 0x0000         # Text rotation.

  header = [record, length].pack('vv')
  data  = [horz_align].pack('C')
  data += [vert_align].pack('C')
  data += [bg_mode].pack('v')
  data += [text_color_rgb].pack('V')
  data += [text_x].pack('V')
  data += [text_y].pack('V')
  data += [text_dx].pack('V')
  data += [text_dy].pack('V')
  data += [grbit1].pack('v')
  data += [text_color_index].pack('v')
  data += [grbit2].pack('v')
  data += [rotation].pack('v')

  append(header, data)
end

#store_dataformat(series_index, series_number, point_number) ⇒ Object

_store_dataformat()

Write the DATAFORMAT chart BIFF record. This record specifies the series that the subsequent sub stream refers to.



1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
# File 'lib/writeexcel/chart.rb', line 1545

def store_dataformat(series_index, series_number, point_number)   # :nodoc:
  record        = 0x1006     # Record identifier.
  length        = 0x0008     # Number of bytes to follow.
  # series_index             # Series index.
  # series_number            # Series number. (Same as index).
  # point_number             # Point number.
  grbit         = 0x0000     # Format flags.

  store_simple(record, length, point_number, series_index, series_number, grbit)
end

#store_dataformat_stream(series_index) ⇒ Object

_store_dataformat_stream()

Write the DATAFORMAT chart substream.



914
915
916
917
918
919
920
# File 'lib/writeexcel/chart.rb', line 914

def store_dataformat_stream(series_index)  # :nodoc:
  store_dataformat(series_index, series_index, 0xFFFF)

  store_begin
  store_3dbarshape
  store_end
end

#store_defaulttextObject

_store_defaulttext()

Write the DEFAULTTEXT chart BIFF record. Identifier for subsequent TEXT record.



1563
1564
1565
1566
1567
1568
1569
# File 'lib/writeexcel/chart.rb', line 1563

def store_defaulttext   # :nodoc:
  record = 0x1024     # Record identifier.
  length = 0x0002     # Number of bytes to follow.
  type   = 0x0002     # Type.

  store_simple(record, length, type)
end

#store_dropbarObject

_store_dropbar()

Write the DROPBAR chart BIFF record.



1577
1578
1579
1580
1581
1582
1583
# File 'lib/writeexcel/chart.rb', line 1577

def store_dropbar   # :nodoc:
  record      = 0x103D     # Record identifier.
  length      = 0x0002     # Number of bytes to follow.
  percent_gap = 0x0096     # Drop bar width gap (%).

  store_simple(record, length, percent_gap)
end

#store_endObject

_store_end()

Write the END chart BIFF record to indicate the end of a sub stream.



1591
1592
1593
1594
1595
1596
# File 'lib/writeexcel/chart.rb', line 1591

def store_end   # :nodoc:
  record = 0x1034     # Record identifier.
  length = 0x0000     # Number of bytes to follow.

  store_simple(record, length)
end

#store_fbi(index, height, width_basis, height_basis, scale_basis) ⇒ Object

_store_fbi()

Write the FBI chart BIFF record. Specifies the font information at the time it was applied to the chart.



1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
# File 'lib/writeexcel/chart.rb', line 1604

def store_fbi(index, height, width_basis, height_basis, scale_basis)  # :nodoc:
  record       = 0x1060    # Record identifier.
  length       = 0x000A    # Number of bytes to follow.
  # index                  # Font index.
  height       = height * 20    # Default font height in twips.
  # width_basis            # Width basis, in twips.
  # height_basis           # Height basis, in twips.
  # scale_basis            # Scale by chart area or plot area.

  store_simple(record, length, width_basis, height_basis, height, scale_basis, index)
end

#store_fontx(index) ⇒ Object

_store_fontx()

Write the FONTX chart BIFF record which contains the index of the FONT record in the Workbook.



1623
1624
1625
1626
1627
1628
1629
# File 'lib/writeexcel/chart.rb', line 1623

def store_fontx(index)   # :nodoc:
  record = 0x1026     # Record identifier.
  length = 0x0002     # Number of bytes to follow.
  # index             # Font index.

  store_simple(record, length, index)
end

#store_frame(frame_type, grbit) ⇒ Object

_store_frame()

Write the FRAME chart BIFF record.



1637
1638
1639
1640
1641
1642
1643
1644
# File 'lib/writeexcel/chart.rb', line 1637

def store_frame(frame_type, grbit)   # :nodoc:
  record     = 0x1032     # Record identifier.
  length     = 0x0004     # Number of bytes to follow.
  # frame_type            # Frame type.
  # grbit                 # Option flags.

  store_simple(record, length, frame_type, grbit)
end

#store_legend(x, y, width, height, wType, wSpacing, grbit) ⇒ Object

_store_legend()

Write the LEGEND chart BIFF record. The Marcus Horan method.



1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
# File 'lib/writeexcel/chart.rb', line 1652

def store_legend(x, y, width, height, wType, wSpacing, grbit)  # :nodoc:
  record   = 0x1015     # Record identifier.
  length   = 0x0014     # Number of bytes to follow.
  # x                   # X-position.
  # y                   # Y-position.
  # width               # Width.
  # height              # Height.
  # wType               # Type.
  # wSpacing            # Spacing.
  # grbit               # Option flags.

  header = [record, length].pack('vv')
  data  = [x].pack('V')
  data += [y].pack('V')
  data += [width].pack('V')
  data += [height].pack('V')
  data += [wType].pack('C')
  data += [wSpacing].pack('C')
  data += [grbit].pack('v')

  append(header, data)
end

#store_legend_streamObject

_store_legend_stream()

Write the LEGEND chart substream.



1198
1199
1200
1201
1202
1203
1204
1205
# File 'lib/writeexcel/chart.rb', line 1198

def store_legend_stream   # :nodoc:
  store_legend(*@config[:legend])

  store_begin
  store_pos(*@config[:legend_pos])
  store_legend_text_stream
  store_end
end

#store_legend_text_streamObject

_store_legend_text_stream()

Write the legend TEXT substream.



999
1000
1001
1002
1003
1004
1005
1006
1007
# File 'lib/writeexcel/chart.rb', line 999

def store_legend_text_stream   # :nodoc:
  store_text(*@config[:legend_text])

  store_begin
  store_pos(*@config[:legend_text_pos])
  store_ai(0, 1, '')

  store_end
end

#store_lineformat(rgb, lns, we, grbit, index) ⇒ Object

_store_lineformat()

Write the LINEFORMAT chart BIFF record.



1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
# File 'lib/writeexcel/chart.rb', line 1681

def store_lineformat(rgb, lns, we, grbit, index)  # :nodoc:
  record = 0x1007     # Record identifier.
  length = 0x000C     # Number of bytes to follow.
  # rgb               # Line RGB colour.
  # lns               # Line pattern.
  # we                # Line weight.
  # grbit             # Option flags.
  # index             # Index to colour of line.

  header = [record, length].pack('vv')
  data  = [rgb].pack('V')
  data += [lns].pack('v')
  data += [we].pack('v')
  data += [grbit].pack('v')
  data += [index].pack('v')

  append(header, data)
end

#store_marker_dataformat_streamObject

_store_marker_dataformat_stream()

This is an abstract method that is overridden by the sub-classes to define properties of markers, linetypes, pie formats and other.



1188
1189
1190
# File 'lib/writeexcel/chart.rb', line 1188

def store_marker_dataformat_stream   # :nodoc:

end

#store_markerformat(rgbFore, rgbBack, marker, grbit, icvFore, icvBack, miSize) ⇒ Object

_store_markerformat()

Write the MARKERFORMAT chart BIFF record.



1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
# File 'lib/writeexcel/chart.rb', line 1706

def store_markerformat(rgbFore, rgbBack, marker, grbit, icvFore, icvBack, miSize)# :nodoc:
  record  = 0x1009     # Record identifier.
  length  = 0x0014     # Number of bytes to follow.
  # rgbFore            # Foreground RGB color.
  # rgbBack            # Background RGB color.
  # marker             # Type of marker.
  # grbit              # Format flags.
  # icvFore            # Color index marker border.
  # icvBack            # Color index marker fill.
  # miSize             # Size of line markers.

  header = [record, length].pack('vv')
  data  = [rgbFore].pack('V')
  data += [rgbBack].pack('V')
  data += [marker].pack('v')
  data += [grbit].pack('v')
  data += [icvFore].pack('v')
  data += [icvBack].pack('v')
  data += [miSize].pack('V')

  append(header, data)
end

_store_objectlink()

Write the OBJECTLINK chart BIFF record.



1735
1736
1737
1738
1739
1740
1741
1742
1743
# File 'lib/writeexcel/chart.rb', line 1735

def store_objectlink(link_type)   # :nodoc:
  record      = 0x1027     # Record identifier.
  length      = 0x0006     # Number of bytes to follow.
  # link_type              # Object text link type.
  link_index1 = 0x0000     # Link index 1.
  link_index2 = 0x0000     # Link index 2.

  store_simple(record, length, link_type, link_index1, link_index2)
end

#store_pieformatObject

_store_pieformat()

Write the PIEFORMAT chart BIFF record.



1751
1752
1753
1754
1755
1756
1757
# File 'lib/writeexcel/chart.rb', line 1751

def store_pieformat   # :nodoc:
  record  = 0x100B     # Record identifier.
  length  = 0x0002     # Number of bytes to follow.
  percent = 0x0000     # Distance % from center.

  store_simple(record, length, percent)
end

#store_plotareaObject

_store_plotarea()

Write the PLOTAREA chart BIFF record. This indicates that the subsequent FRAME record belongs to a plot area.



1766
1767
1768
1769
1770
1771
# File 'lib/writeexcel/chart.rb', line 1766

def store_plotarea   # :nodoc:
  record = 0x1035     # Record identifier.
  length = 0x0000     # Number of bytes to follow.

  store_simple(record, length)
end

#store_plotarea_frame_streamObject

_store_plotarea_frame_stream()

Write the FRAME chart substream.



1103
1104
1105
# File 'lib/writeexcel/chart.rb', line 1103

def store_plotarea_frame_stream   # :nodoc:
  store_area_frame_stream_common(:plot)
end

#store_plotgrowthObject

_store_plotgrowth()

Write the PLOTGROWTH chart BIFF record.



1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
# File 'lib/writeexcel/chart.rb', line 1779

def store_plotgrowth  # :nodoc:
  record  = 0x1064         # Record identifier.
  length  = 0x0008         # Number of bytes to follow.
  dx_plot = 0x00010000     # Horz growth for font scale.
  dy_plot = 0x00010000     # Vert growth for font scale.

  header = [record, length].pack('vv')
  data  = [dx_plot].pack('V')
  data += [dy_plot].pack('V')

  append(header, data)
end

#store_pos(mdTopLt, mdBotRt, x1, y1, x2, y2) ⇒ Object

_store_pos()

Write the POS chart BIFF record. Generally not required when using automatic positioning.



1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
# File 'lib/writeexcel/chart.rb', line 1799

def store_pos(mdTopLt, mdBotRt, x1, y1, x2, y2)  # :nodoc:
  record  = 0x104F     # Record identifier.
  length  = 0x0014     # Number of bytes to follow.
  # mdTopLt            # Top left.
  # mdBotRt            # Bottom right.
  # x1                 # X coordinate.
  # y1                 # Y coordinate.
  # x2                 # Width.
  # y2                 # Height.

  header = [record, length].pack('vv')
  data  = [mdTopLt].pack('v')
  data += [mdBotRt].pack('v')
  data += [x1].pack('V')
  data += [y1].pack('V')
  data += [x2].pack('V')
  data += [y2].pack('V')

  append(header, data)
end

#store_serauxtrend(reg_type, poly_order, equation, r_squared) ⇒ Object

_store_serauxtrend()

Write the SERAUXTREND chart BIFF record.



1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
# File 'lib/writeexcel/chart.rb', line 1826

def store_serauxtrend(reg_type, poly_order, equation, r_squared)  # :nodoc:
  record     = 0x104B     # Record identifier.
  length     = 0x001C     # Number of bytes to follow.
  # reg_type              # Regression type.
  # poly_order            # Polynomial order.
  # equation              # Display equation.
  # r_squared             # Display R-squared.
  # intercept             # Forced intercept.
  # forecast              # Forecast forward.
  # backcast              # Forecast backward.

  # TODO. When supported, intercept needs to be NAN if not used.
  # Also need to reverse doubles.
  intercept = ['FFFFFFFF0001FFFF'].pack('H*')
  forecast  = ['0000000000000000'].pack('H*')
  backcast  = ['0000000000000000'].pack('H*')

  header = [record, length].pack('vv')
  data  = [reg_type].pack('C')
  data += [poly_order].pack('C')
  data += intercept
  data += [equation].pack('C')
  data += [r_squared].pack('C')
  data += forecast
  data += backcast

  append(header, data)
end

#store_series(category_count, value_count) ⇒ Object

_store_series()

Write the SERIES chart BIFF record.



1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
# File 'lib/writeexcel/chart.rb', line 1861

def store_series(category_count, value_count)  # :nodoc:
  record         = 0x1003     # Record identifier.
  length         = 0x000C     # Number of bytes to follow.
  category_type  = 0x0001     # Type: category.
  value_type     = 0x0001     # Type: value.
  # category_count            # Num of categories.
  # value_count               # Num of values.
  bubble_type    = 0x0001     # Type: bubble.
  bubble_count   = 0x0000     # Num of bubble values.

  store_simple(record, length, category_type, value_type,
               category_count, value_count, bubble_type, bubble_count)
end

#store_series_stream(params) ⇒ Object

_store_series_stream()

Write the SERIES chart substream.



884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
# File 'lib/writeexcel/chart.rb', line 884

def store_series_stream(params)   # :nodoc:
  name_type     = _formula_type_from_param(2, 1, params, :name_formula)
  value_type    = _formula_type_from_param(2, 0, params, :value_formula)
  category_type = _formula_type_from_param(2, 0, params, :category_formula)

  store_series(params[:value_count], params[:category_count])

  store_begin

  # Store the Series name AI record.
  store_ai(0, name_type, params[:name_formula])
  unless params[:name].nil?
    store_seriestext(params[:name], params[:name_encoding])
  end

  store_ai(1, value_type,    params[:value_formula])
  store_ai(2, category_type, params[:category_formula])
  store_ai(3, 1,             '' )

  store_dataformat_stream(params[:index])
  store_sertocrt
  store_end
end

#store_series_text_stream(font_index) ⇒ Object

_store_series_text_stream()

Write the series TEXT substream.



928
929
930
931
932
933
934
935
936
# File 'lib/writeexcel/chart.rb', line 928

def store_series_text_stream(font_index)  # :nodoc:
  store_text(*@config[:series_text])

  store_begin
  store_pos(*@config[:series_text_pos])
  store_fontx( font_index )
  store_ai( 0, 1, '' )
  store_end
end

#store_seriestext(str, encoding) ⇒ Object

_store_seriestext()

Write the SERIESTEXT chart BIFF record.



1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
# File 'lib/writeexcel/chart.rb', line 1881

def store_seriestext(str, encoding)  # :nodoc:
  ruby_19 { str = convert_to_ascii_if_ascii(str) }

  record   = 0x100D          # Record identifier.
  length   = 0x0000          # Number of bytes to follow.
  id       = 0x0000          # Text id.
  # str                      # Text.
  # encoding                 # String encoding.
  cch      = str.bytesize      # String length.

  encoding ||= 0

  # Character length is num of chars not num of bytes
  cch /= 2 if encoding != 0

  # Change the UTF-16 name from BE to LE
  str = str.unpack('v*').pack('n*') if encoding != 0

  length = 4 + str.bytesize

  header = [record, length].pack('vv')
  data  = [id].pack('v')
  data += [cch].pack('C')
  data += [encoding].pack('C')

  append(header, data, str)
end

#store_serparent(series) ⇒ Object

_store_serparent()

Write the SERPARENT chart BIFF record.



1915
1916
1917
1918
1919
1920
1921
# File 'lib/writeexcel/chart.rb', line 1915

def store_serparent(series)  # :nodoc:
  record = 0x104A     # Record identifier.
  length = 0x0002     # Number of bytes to follow.
  # series            # Series parent.

  store_simple(record, length, series)
end

#store_sertocrtObject

_store_sertocrt()

Write the SERTOCRT chart BIFF record to indicate the chart group index.



1929
1930
1931
1932
1933
1934
1935
# File 'lib/writeexcel/chart.rb', line 1929

def store_sertocrt   # :nodoc:
  record     = 0x1045     # Record identifier.
  length     = 0x0002     # Number of bytes to follow.
  chartgroup = 0x0000     # Chart group index.

  store_simple(record, length, chartgroup)
end

#store_shtpropsObject

_store_shtprops()

Write the SHTPROPS chart BIFF record.



1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
# File 'lib/writeexcel/chart.rb', line 1943

def store_shtprops   # :nodoc:
  record      = 0x1044     # Record identifier.
  length      = 0x0004     # Number of bytes to follow.
  grbit       = 0x000E     # Option flags.
  empty_cells = 0x0000     # Empty cell handling.

  grbit = 0x000A if @embedded

  store_simple(record, length, grbit, empty_cells)
end

#store_text(x, y, dx, dy, grbit1, grbit2, rotation = 0x00) ⇒ Object

_store_text()

Write the TEXT chart BIFF record.



1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
# File 'lib/writeexcel/chart.rb', line 1960

def store_text(x, y, dx, dy, grbit1, grbit2, rotation = 0x00)# :nodoc:
  record   = 0x1025            # Record identifier.
  length   = 0x0020            # Number of bytes to follow.
  at       = 0x02              # Horizontal alignment.
  vat      = 0x02              # Vertical alignment.
  wBkgMode = 0x0001            # Background display.
  rgbText  = 0x0000            # Text RGB colour.
  # x                          # Text x-pos.
  # y                          # Text y-pos.
  # dx                         # Width.
  # dy                         # Height.
  # grbit1                     # Option flags.
  icvText  = 0x004D            # Auto Colour.
  # grbit2                     # Show legend.
  # rotation                   # Show value.

  header = [record, length].pack('vv')
  data  = [at].pack('C')
  data += [vat].pack('C')
  data += [wBkgMode].pack('v')
  data += [rgbText].pack('V')
  data += [x].pack('V')
  data += [y].pack('V')
  data += [dx].pack('V')
  data += [dy].pack('V')
  data += [grbit1].pack('v')
  data += [icvText].pack('v')
  data += [grbit2].pack('v')
  data += [rotation].pack('v')

  append(header, data)
end

#store_tickObject

_store_tick()

Write the TICK chart BIFF record.



1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
# File 'lib/writeexcel/chart.rb', line 1999

def store_tick   # :nodoc:
  record    = 0x101E         # Record identifier.
  length    = 0x001E         # Number of bytes to follow.
  tktMajor  = 0x02           # Type of major tick mark.
  tktMinor  = 0x00           # Type of minor tick mark.
  tlt       = 0x03           # Tick label position.
  wBkgMode  = 0x01           # Background mode.
  rgb       = 0x00000000     # Tick-label RGB colour.
  reserved1 = 0x00000000     # Reserved.
  reserved2 = 0x00000000     # Reserved.
  reserved3 = 0x00000000     # Reserved.
  reserved4 = 0x00000000     # Reserved.
  grbit     = 0x0023         # Option flags.
  index     = 0x004D         # Colour index.
  reserved5 = 0x0000         # Reserved.

  header = [record, length].pack('vv')
  data  = [tktMajor].pack('C')
  data += [tktMinor].pack('C')
  data += [tlt].pack('C')
  data += [wBkgMode].pack('C')
  data += [rgb].pack('V')
  data += [reserved1].pack('V')
  data += [reserved2].pack('V')
  data += [reserved3].pack('V')
  data += [reserved4].pack('V')
  data += [grbit].pack('v')
  data += [index].pack('v')
  data += [reserved5].pack('v')

  append(header, data)
end

#store_title_text_streamObject

_store_title_text_stream()

Write the title TEXT substream.



1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
# File 'lib/writeexcel/chart.rb', line 1015

def store_title_text_stream   # :nodoc:
  formula = @title_formula
  ai_type = _formula_type(2, 1, formula)

  store_text(*@config[:title_text])

  store_begin
  store_pos(*@config[:title_text_pos])
  store_fontx(7)
  store_ai(0, ai_type, formula)

  unless @title_name.nil?
    store_seriestext(@title_name, @title_encoding)
  end

  store_objectlink(1)
  store_end
end

#store_valuerangeObject

_store_valuerange()

Write the VALUERANGE chart BIFF record.



2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
# File 'lib/writeexcel/chart.rb', line 2038

def store_valuerange   # :nodoc:
  record   = 0x101F         # Record identifier.
  length   = 0x002A         # Number of bytes to follow.
  numMin   = 0x00000000     # Minimum value on axis.
  numMax   = 0x00000000     # Maximum value on axis.
  numMajor = 0x00000000     # Value of major increment.
  numMinor = 0x00000000     # Value of minor increment.
  numCross = 0x00000000     # Value where category axis crosses.
  grbit    = 0x011F         # Format flags.

  # TODO. Reverse doubles when they are handled.

  header = [record, length].pack('vv')
  data  = [numMin].pack('d')
  data += [numMax].pack('d')
  data += [numMajor].pack('d')
  data += [numMinor].pack('d')
  data += [numCross].pack('d')
  data += [grbit].pack('v')

  append(header, data)
end

#store_window2Object

_store_window2(), overridden.

Write BIFF record Window2. Note, this overrides the parent Worksheet record because the Chart version of the record is smaller and is used mainly to indicate if the chart tab is selected or not.



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
# File 'lib/writeexcel/chart.rb', line 586

def store_window2   # :nodoc:
  record  = 0x023E     # Record identifier
  length  = 0x000A     # Number of bytes to follow
  grbit   = 0x0000     # Option flags
  rwTop   = 0x0000     # Top visible row
  colLeft = 0x0000     # Leftmost visible column
  rgbHdr  = 0x0000     # Row/col heading, grid color

  # The options flags that comprise grbit
  fDspFmla       = 0                      # 0 - bit
  fDspGrid       = 0                      # 1
  fDspRwCol      = 0                      # 2
  fFrozen        = 0                      # 3
  fDspZeros      = 0                      # 4
  fDefaultHdr    = 0                      # 5
  fArabic        = 0                      # 6
  fDspGuts       = 0                      # 7
  fFrozenNoSplit = 0                      # 0 - bit
  fSelected      = @selected              # 1
  fPaged         = 0                      # 2
  fBreakPreview  = 0                      # 3

  #<<< Perltidy ignore this.
  grbit             = fDspFmla
  grbit            |= fDspGrid       << 1
  grbit            |= fDspRwCol      << 2
  grbit            |= fFrozen        << 3
  grbit            |= fDspZeros      << 4
  grbit            |= fDefaultHdr    << 5
  grbit            |= fArabic        << 6
  grbit            |= fDspGuts       << 7
  grbit            |= fFrozenNoSplit << 8
  grbit            |= fSelected      << 9
  grbit            |= fPaged         << 10
  grbit            |= fBreakPreview  << 11
  #>>>

  header = [record, length].pack("vv")
  data = [grbit, rwTop, colLeft, rgbHdr].pack("vvvV")

  append(header, data)
end

#store_x_axis_text_streamObject

_store_x_axis_text_stream()

Write the X-axis TEXT substream.



949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
# File 'lib/writeexcel/chart.rb', line 949

def store_x_axis_text_stream   # :nodoc:
  formula = @x_axis_formula.nil? ? '' : @x_axis_formula
  ai_type = _formula_type(2, 1, formula)

  store_text(*@config[:x_axis_text])

  store_begin
  store_pos(*@config[:x_axis_text_pos])
  store_fontx(8)
  store_ai(0, ai_type, formula)

  unless @x_axis_name.nil?
    store_seriestext(@x_axis_name, @x_axis_encoding)
  end

  store_objectlink(3)
  store_end
end

#store_y_axis_text_streamObject

_store_y_axis_text_stream()

Write the Y-axis TEXT substream.



974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
# File 'lib/writeexcel/chart.rb', line 974

def store_y_axis_text_stream   # :nodoc:
  formula = @y_axis_formula
  ai_type = _formula_type(2, 1, formula)

  store_text(*@config[:y_axis_text])

  store_begin
  store_pos(*@config[:y_axis_text_pos])
  store_fontx(8)
  store_ai(0, ai_type, formula)

  unless @y_axis_name.nil?
    store_seriestext(@y_axis_name, @y_axis_encoding)
  end

  store_objectlink(2)
  store_end
end

#using_tmpfile=(val) ⇒ Object

:nodoc:



478
479
480
# File 'lib/writeexcel/chart.rb', line 478

def using_tmpfile=(val)  # :nodoc:
  @using_tmpfile = val
end