class ExcelWps::Chart

图表

Constants

BarClustered
ChartStyle
ChartType
ColumnClustered

图形类型

ColumnStacked
DataLabelsShowLabel

标签数据

DataLabelsShowLabelAndPercent
DataLabelsShowPercent
DataLabelsShowValue
Doughnut
HasTitle
Line
MajorUnit
MinorUnit
Pie
Position
Separator
ShowCategoryName
ShowLegendKey
ShowSeriesName
ShowValue
Text

Public Class Methods

new(active) click to toggle source
# File lib/excel_wps.rb, line 331
def initialize(active)
        @chart = active
end

Public Instance Methods

axes_unit(int) click to toggle source

设置坐标轴格式, 刻度单位

# File lib/excel_wps.rb, line 378
def axes_unit(int)
        @chart.Axes(2).MajorUnit = int
        @chart.Axes(2).MinorUnit = int
end
axes_x=(name) click to toggle source

设置X轴名称, 只用于条形图

# File lib/excel_wps.rb, line 366
def axes_x=(name)
        @chart.Axes(1,1).HasTitle = true
        @chart.Axes(1,1).AxisTitle.Characters.Text = name
end
axes_y=(name) click to toggle source

设置Y轴名称, 只用于条形图

# File lib/excel_wps.rb, line 372
def axes_y=(name)
        @chart.Axes(2,1).HasTitle = true
        @chart.Axes(2,1).AxisTitle.Characters.Text = name
end
category_name=(bool) click to toggle source

标签类别名称开关

# File lib/excel_wps.rb, line 415
def category_name=(bool)
        now_table do |n|
                n.ShowCategoryName = bool
        end
end
chart_work() click to toggle source
# File lib/excel_wps.rb, line 335
def chart_work
        @chart
end
data_label(type=DataLabelsShowLabelAndPercent) click to toggle source

添加饼图的百分比

# File lib/excel_wps.rb, line 393
def data_label(type=DataLabelsShowLabelAndPercent)

        # 应用标签选项
        @chart.ApplyDataLabels(type)

        # 取消标签选项的系列名称
        now = @chart.SeriesCollection(1).DataLabels
        now.ShowSeriesName = false

        # 将图例放到右边
        now = @chart.Legend
        now.Position = -4152
end
now_table() { |chart.SeriesCollection(t).DataLabels| ... } click to toggle source

标签选项

# File lib/excel_wps.rb, line 340
def now_table
        #@chart.SeriesCollection(n).DataLabels
        num = @chart.SeriesCollection.Count
        num.times do |t|
                t += 1
                yield @chart.SeriesCollection(t).DataLabels
        end
end
series_name=(bool) click to toggle source

标签系列名称开关

# File lib/excel_wps.rb, line 408
def series_name=(bool)
        now_table do |n|
                n.ShowSeriesName = bool
        end
end
source=(range) click to toggle source

这是原数据地址, 以每列数据作为一个系列

# File lib/excel_wps.rb, line 356
def source=(range)
        @chart.SetSourceData(range, 2)
end
style=(int) click to toggle source

修改样式 通过录制宏可以查看样式编号 条形图中203 比较好看 饼图中 251, 254 比较好看

# File lib/excel_wps.rb, line 387
def style=(int)
        @chart.ChartStyle = int
        data_label
end
title=(name) click to toggle source

修改标题

# File lib/excel_wps.rb, line 350
def title=(name)
        @chart.HasTitle = true
        @chart.ChartTitle.Characters.Text = name
end
type=(c_type) click to toggle source

更改图形类型

# File lib/excel_wps.rb, line 361
def type=(c_type)
        @chart.ChartType = c_type
end
value=(bool) click to toggle source

标签值开关

# File lib/excel_wps.rb, line 422
def value=(bool)
        now_table do |n|
                n.ShowValue = bool
                n.ShowLegendKey = 0 unless bool
                n.Separator = " " unless bool
        end
end