HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// create column chart
3
var chart = anychart.column();
4
5
var dataSet = anychart.data.set([
6
['Lip gloss', 22998, 12043],
7
['Eyeliner', 12321, 15067],
8
['Eyeshadows', 12998, 12043],
9
['Powder', 10261, 14419],
10
['Mascara', 11261, 10419]
11
]);
12
13
// set chart title
14
chart.title('Top 5 Products by Revenue in two Regions');
15
16
// map data for the first series, take x from the zero column and value from the first column of data set
17
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
18
19
// map data for the second series, take x from the zero column and value from the second column of data set
20
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
21
22
// create first series with mapped data
23
var seriesFirst = chart.column(firstSeriesData);
24
seriesFirst.name('Florida');
25
26
var shapes = seriesFirst.rendering().shapes();
27
28
seriesFirst.color('#3F9CD7');
29
// set rendering settings
30
seriesFirst
31
.rendering()
32
// set point function to drawing
33
.point(drawer)
34
// set update point function to drawing, change the point shape when the state changes
35
.updatePoint(drawer)
36
// set shapes
37
.shapes(shapes);
38
39
var seriesSecond = chart.column(secondSeriesData);
40
seriesSecond
41
.name('Texas')
42
.color('#F37E59')
43
.stroke(anychart.color.darken(this.sourceColor, 1));
44
// set rendering settings
45
seriesSecond
46
.rendering()
47
// set point function to drawing
48
.point(drawer)
49
// set update point function to drawing, change the point shape when the state changes
50
.updatePoint(drawer)
51
// set shapes
52
.shapes(shapes);
53
54
// set titles for Y-axis
55
chart.yAxis().title('Revenue in Dollars');
56
// set minimum for y-scale
57
chart.yScale().minimum(0);
58
// set tooltip prefix
59
chart.tooltip().valuePrefix('$');
60
// turn on legend
61
chart.legend(true);
62
// set container id for the chart
63
chart.container('container');
64
// initiate chart drawing
65
chart.draw();
66
});
67
68
function drawer() {
69
// if missing (not correct data), then skipping this point drawing
70
if (this.missing) {
71
return;
72
}
73
74
// get shapes group
75
var shapes = this.shapes || this.getShapesGroup(this.pointState);
76
// calculate the left value of the x-axis
77
var leftX = this.x - this.pointWidth / 2;
78
// calculate the right value of the x-axis
79
var rightX = leftX + this.pointWidth;
80
// calculate the half of point width
81
var rx = this.pointWidth / 2;
82
83
shapes.path
84
// resets all 'line' operations
85
.clear()
86
// draw column with rounded edges
87
.moveTo(leftX, this.zero)
88
.lineTo(leftX, this.value + rx)
89
.circularArc(leftX + rx, this.value + rx, rx, rx, 180, 180)
90
.lineTo(rightX, this.zero)
91
// close by connecting the last point with the first straight line
92
.close();
93
}