HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// create a chart
3
var chart = anychart.column();
4
5
// create data set on our data
6
var data = [
7
{x: 'Apr', low: 29, high: 37},
8
{x: 'May'},
9
{x: 'Jun', low: 29, high: 47},
10
{x: 'Jul', low: 12, high: 27},
11
{x: 'Aug', low: 20, high: 33, color: "#ff0000"},
12
{x: 'Sep', low: 35, high: 44},
13
{x: 'Oct', low: 20, high: 31},
14
{x: 'Nov', low: 44, high: 51}
15
];
16
17
// create a range column series
18
var series = chart.rangeColumn(data);
19
// set a meta field to use as a cherry size
20
// series.meta("cherry", 50);
21
// set a meta field to use as a stem thickness
22
// series.meta("stem", 1);
23
24
// optional: configurable select fill
25
series.selected().fill("white");
26
27
// call a custom function that changes series rendering
28
cherryChartRendering(series);
29
30
// set container id for the chart and initiate chart drawing
31
chart.container('container').draw();
32
});
33
34
// custom function to change range column series rendering to
35
// cherry chart with a special value line markers
36
function cherryChartRendering(series){
37
// cherry fill color
38
series.fill(function () {
39
// check if color is set for the point and use it or series color
40
color = this.iterator.get("color") || this.sourceColor;
41
return anychart.color.lighten(color, 0.25);
42
});
43
// cherry stroke color
44
series.stroke(function () {
45
// check if color is set for the point and use it or series color
46
color = this.iterator.get("color") || this.sourceColor;
47
return anychart.color.darken(color, 0.1);
48
});
49
50
// set rendering settings
51
series.rendering()
52
// set point function to drawing
53
.point(drawer)
54
}
55
56
// custom drawer function to draw a
57
function drawer() {
58
59
// if missing - skip drawing
60
if (this.missing) {
61
return;
62
}
63
64
// get cherry size or set default
65
var cherry = this.series.meta("cherry") || (this.categoryWidth / 15);
66
// get stem thickness or set default
67
var stem = this.series.meta("stem") || (this.categoryWidth / 50);
68
69
// get shapes group
70
var shapes = this.shapes || this.getShapesGroup(this.pointState);
71
// calculate the left value of the x-axis
72
var leftX = this.x - stem / 2;
73
// calculate the right value of the x-axis
74
var rightX = leftX + stem / 2;
75
76
shapes['path']
77
// resets all 'path' operations
78
.clear()
79
// draw bulb
80
.moveTo(leftX, this.low - cherry)
81
.lineTo(leftX, this.high)
82
.lineTo(rightX, this.high)
83
.lineTo(rightX, this.low - cherry)
84
.arcToByEndPoint(leftX, this.low - cherry, cherry, cherry, true, true)
85
// close by connecting the last point with the first
86
.close();
87
}