Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding in axis line fill and patching view3d misname for line3DChart

  • Loading branch information...
commit 7af812c429ffd2374f164fe2f1f4f19ba6cb5f64 1 parent e121fe8
@randym authored
View
21 examples/chart_colors.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby -w -s
# -*- coding: utf-8 -*-
-# $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
require 'axlsx'
p = Axlsx::Package.new
@@ -36,7 +36,7 @@
sheet.add_row ["First", "Second", "Third", "Fourth"]
sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
- chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF']
+ chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF', '000000']
end
end
@@ -45,7 +45,7 @@
wb.add_worksheet(:name => "Line Chart") do |sheet|
sheet.add_row ["First", 1, 5, 7, 9]
sheet.add_row ["Second", 5, 2, 14, 9]
- sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 20) do |chart|
+ sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 30) do |chart|
chart.start_at 0, 2
chart.end_at 10, 15
chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"], :color => "FF0000"
@@ -53,6 +53,21 @@
end
end
+wb.add_worksheet(:name => 'Line Chart with Axis colors') do |sheet|
+ sheet.add_row ["First", 1, 5, 7, 9]
+ sheet.add_row ["Second", 5, 2, 14, 9]
+ sheet.add_chart(Axlsx::Line3DChart, :title => "example 7: Flat Line Chart", :rot_x => 0, :perspective => 0) do |chart|
+ chart.valAxis.color = "FFFF00"
+ chart.catAxis.color = "00FFFF"
+ chart.serAxis.delete = true
+ chart.start_at 0, 2
+ chart.end_at 10, 15
+ chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"], :color => "FF0000"
+ chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"], :color => "00FF00"
+ end
+
+end
+
##Generating A Scatter Chart
wb.add_worksheet(:name => "Scatter Chart") do |sheet|
View
20 lib/axlsx/drawing/axis.rb
@@ -3,6 +3,13 @@ module Axlsx
# the access class defines common properties and values for a chart axis.
class Axis
+
+
+ # the fill color to use in the axis shape properties. This should be a 6 character long hex string
+ # e.g. FF0000 for red
+ # @return [String]
+ attr_reader :color
+
# the id of the axis.
# @return [Integer]
attr_reader :ax_id
@@ -70,7 +77,7 @@ def initialize(ax_id, cross_ax, options={})
@format_code = "General"
@delete = @label_rotation = 0
@scaling = Scaling.new(:orientation=>:minMax)
- @title = nil
+ @title = @color = nil
self.ax_pos = :b
self.tick_lbl_pos = :nextTo
self.format_code = "General"
@@ -81,6 +88,9 @@ def initialize(ax_id, cross_ax, options={})
end
end
+ def color=(color_rgb)
+ @color = color_rgb
+ end
# The position of the axis
# must be one of [:l, :r, :t, :b]
def ax_pos=(v) RestrictionValidator.validate "#{self.class}.ax_pos", [:l, :r, :b, :t], v; @ax_pos = v; end
@@ -140,6 +150,7 @@ def to_xml_string(str = '')
str << '<c:delete val="'<< @delete.to_s << '"/>'
str << '<c:axPos val="' << @ax_pos.to_s << '"/>'
str << '<c:majorGridlines>'
+ # TODO shape properties need to be extracted into a class
if gridlines == false
str << '<c:spPr>'
str << '<a:ln>'
@@ -153,6 +164,13 @@ def to_xml_string(str = '')
str << '<c:majorTickMark val="none"/>'
str << '<c:minorTickMark val="none"/>'
str << '<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>'
+ # TODO - this is also being used for series colors
+ # time to extract this into a class spPr - Shape Properties
+ if @color
+ str << '<c:spPr><a:ln><a:solidFill>'
+ str << '<a:srgbClr val="' << @color << '"/>'
+ str << '</a:solidFill></a:ln></c:spPr>'
+ end
# some potential value in implementing this in full. Very detailed!
str << '<c:txPr><a:bodyPr rot="' << @label_rotation.to_s << '"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>'
str << '<c:crossAx val="' << @cross_ax.to_s << '"/>'
View
2  lib/axlsx/drawing/line_3D_chart.rb
@@ -70,7 +70,7 @@ def initialize(frame, options={})
@serAxis = SerAxis.new(@serAxId, @valAxId)
super(frame, options)
@series_type = LineSeries
- @view3D = View3D.new({:perspective=>30}.merge(options))
+ @view_3D = View3D.new({:perspective=>30}.merge(options))
end
# @see grouping
View
8 test/drawing/tc_axis.rb
@@ -19,6 +19,14 @@ def test_initialization
assert_equal('Foo', @axis.title.text)
end
+ def test_color
+ @axis.color = "00FF00"
+ str = '<?xml version="1.0" encoding="UTF-8"?>'
+ str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '">'
+ doc = Nokogiri::XML(@axis.to_xml_string(str))
+ assert(doc.xpath("//a:srgbClr[@val='00FF00']"))
+ end
+
def test_cell_based_axis_title
p = Axlsx::Package.new
p.workbook.add_worksheet(:name=>'foosheet') do |sheet|
Please sign in to comment.
Something went wrong with that request. Please try again.