3
4
5
6
7
8
9
10
11
12
13
14
15
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/asposeslidesjava/Charts/setpiechartcolors.rb', line 3
def initialize()
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
pres = Rjb::import('com.aspose.slides.Presentation').new
sld = pres.getSlides().get_Item(0)
chart_type = Rjb::import('com.aspose.slides.ChartType')
chart = sld.getShapes().addChart(chart_type.Pie, 100, 100, 400, 400)
chart.getChartTitle().addTextFrameForOverriding("Sample Title")
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(Rjb::import('com.aspose.slides.NullableBool').True)
chart.getChartTitle().setHeight(20)
chart.hasTitle(true)
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true)
defaultWorksheetIndex = 0
fact = chart.getChartData().getChartDataWorkbook()
chart.getChartData().getSeries().clear()
chart.getChartData().getCategories().clear()
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr"))
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr"))
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr"))
series = chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType())
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20))
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50))
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30))
chart.getChartData().getSeriesGroups().get_Item(0).isColorVaried(true)
fill_type = Rjb::import('com.aspose.slides.FillType')
line_style = Rjb::import('com.aspose.slides.LineStyle')
color = Rjb::import('java.awt.Color')
line_dash_style = Rjb::import('com.aspose.slides.LineDashStyle')
preset_color = Rjb::import('com.aspose.slides.PresetColor')
point = series.getDataPoints().get_Item(0)
point.getFormat().getFill().setFillType(fill_type.Solid)
point.getFormat().getFill().getSolidFillColor().setColor(color.CYAN)
point.getFormat().getLine().getFillFormat().setFillType(fill_type.Solid)
point.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(color.GRAY)
point.getFormat().getLine().setWidth(3.0)
point.getFormat().getLine().setStyle(line_style.ThinThick)
point.getFormat().getLine().setDashStyle(line_dash_style.DashDot)
point1 = series.getDataPoints().get_Item(1)
point1.getFormat().getFill().setFillType(fill_type.Solid)
point1.getFormat().getFill().getSolidFillColor().setColor(Rjb::import('java.awt.Color').new(preset_color.Brown))
point1.getFormat().getLine().getFillFormat().setFillType(fill_type.Solid)
point1.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(color.BLUE)
point1.getFormat().getLine().setWidth(3.0)
point1.getFormat().getLine().setStyle(line_style.Single)
point1.getFormat().getLine().setDashStyle(line_dash_style.LargeDashDot)
point2 = series.getDataPoints().get_Item(2)
point2.getFormat().getFill().setFillType(fill_type.Solid)
point2.getFormat().getFill().getSolidFillColor().setColor(Rjb::import('java.awt.Color').new(preset_color.Coral))
point2.getFormat().getLine().getFillFormat().setFillType(fill_type.Solid)
point2.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(color.RED)
point2.getFormat().getLine().setWidth(2.0)
point2.getFormat().getLine().setStyle(line_style.ThinThin)
point2.getFormat().getLine().setDashStyle(line_dash_style.LargeDashDotDot)
lbl1 = series.getDataPoints().get_Item(0).getLabel()
lbl1.getDataLabelFormat().setShowValue(true)
lbl2 = series.getDataPoints().get_Item(1).getLabel()
lbl2.getDataLabelFormat().setShowValue (true)
lbl2.getDataLabelFormat().setShowLegendKey(true)
lbl2.getDataLabelFormat().setShowPercentage(true)
lbl3 = series.getDataPoints().get_Item(2).getLabel()
lbl3.getDataLabelFormat().setShowSeriesName(true)
lbl3.getDataLabelFormat().setShowPercentage (true)
series.getLabels().getDefaultDataLabelFormat().setShowLeaderLines(true)
chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180)
pres.save(data_dir + "AsposePieChart.pptx", Rjb::import('com.aspose.slides.SaveFormat').Pptx)
puts "Set pie chart sector colors, please check the output file."
end
|