-
Notifications
You must be signed in to change notification settings - Fork 4
/
chart_pie_colors.bas
71 lines (51 loc) · 2.23 KB
/
chart_pie_colors.bas
1
2
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
/'
* An example of creating an Excel pie chart with user defined colors using
* the libxlsxwriter library.
*
* In general formatting is applied to an entire series in a chart. However,
* it is occasionally required to format individual points in a series. In
* particular this is required for Pie/Doughnut charts where each segment is
* represented by a point.
* Copyright 2014-2017, John McNamara, [email protected]
*
* translated by Lee June by using https://github.com/retsyo/libxlsxwriter_freebasic
'/
#include "auto_xlsxwriter.bi"
/'
* Create a worksheet with an example Pie chart.
'/
function main() as Integer
var workbook = new_workbook("chart_pie_colors.xlsx")
var worksheet = workbook_add_worksheet(workbook, NULL)
/' Write some data for the chart. '/
worksheet_write_string(worksheet, CELL("A1"), "Pass", NULL)
worksheet_write_string(worksheet, CELL("A2"), "Fail", NULL)
worksheet_write_number(worksheet, CELL("B1"), 90, NULL)
worksheet_write_number(worksheet, CELL("B2"), 10, NULL)
/' Create a pie chart. '/
var chart = workbook_add_chart(workbook, LXW_CHART_PIE)
/' Add the data series to the chart. '/
var series = chart_add_series(chart, "=Sheet1!$A$1:$A$2", _
"=Sheet1!$B$1:$B$2")
/' Create some fills for the chart points/segments. '/
Dim As lxw_chart_fill red_fill
red_fill.color = LXW_COLOR_RED
Dim As lxw_chart_fill green_fill
green_fill.color = LXW_COLOR_GREEN
/' Add the fills to the point objects. '/
Dim As lxw_chart_point red_point
red_point.fill = @red_fill
Dim As lxw_chart_point green_point
green_point.fill = @green_fill
/' Create an array of pointer to chart points. Note, the array should be
* NULL terminated. '/
Dim As lxw_chart_point ptr points(...) = {@green_point, _
@red_point, _
NULL}
/' Add the points to the series. '/
chart_series_set_points(series, @points(0))
/' Insert the chart into the worksheet. '/
worksheet_insert_chart(worksheet, CELL("D2"), chart)
return workbook_close(workbook)
End Function
main()