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 data set on our data
3
var dataSet = anychart.data.set([
4
['2003', , 4213339.28001, 4878087.10035],
5
['2004', 8.97683285873656, 4401057.002, 5506491.529],
6
['2005', -13.2675486058641, 5110120.477, 6111916.871],
7
['2006', 11.4806616842138, 5748225.103, 6762176.387],
8
['2007', 9.75582014674417, 6742757.691, 6988136.068],
9
['2008', -6.39263867601235, 6671569.243, 6181558.091],
10
['2009', -12.6734866532522, 5455108.53293, 5769079.42387],
11
['2010', 2.1192893978213, 5321089.75701, 6140971.22515],
12
['2011', 2.21127336161004, 5783519.79197, 5931998.69138],
13
['2012', -0.502330583436319, 5843582.595, 5813085.256],
14
['2013', 1.70615173866291, 5907446.8367, 5948101.45551],
15
['2014', 4.68760413430363, 5905830.13882, 6505459.32528],
16
['2015', 1.49017076690518, 6001370.06508, 6594868.80641],
17
['2016', 3.77570237046274, 6253802.32319, 6818033.03796],
18
['2017', 9.680169801945, 6570557.3141, 7766653.90624],
19
['2018', 4.32448608701807, 7309835.234, 7647386.69083],
20
['2019', 3.13162624740104, 7455285.66816, 7970340.54435],
21
['2020', -9.13, 7161973, 6855081],
22
['2021', 5.75, 8750000, 7581111]
23
]);
24
25
// map data for the first series, take x from the zero column and value from the first column of data set
26
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
27
28
// map data for the second series, take x from the zero column and value from the second column of data set
29
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
30
31
// map data for the third series, take x from the zero column and value from the third column of data set
32
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
33
34
// create column chart
35
var chart = anychart.column();
36
37
// helper function to setup label settings for all series
38
var setupSeriesLabels = function (series, name) {
39
series.name(name).stroke('3 #f90 1');
40
series.hovered().stroke('3 #000 1');
41
};
42
43
// turn on chart animation
44
chart.animation(true);
45
46
// set chart title text settings
47
chart.title(
48
'Testing gráficos combinados'
49
);
50
51
// force chart scale to stuck series values
52
chart.yScale().stackMode('value');
53
54
// create scale for line series and extraYAxis
55
// it force line series to not stuck with over series
56
var scale = anychart.scales.linear();
57
scale.minimum(-15).maximum(15).ticks({ interval: 5 });
58
59
// create extra axis on the right side of chart
60
// and set scale for it
61
var extraYAxis = chart.yAxis(1);
62
extraYAxis.orientation('right').scale(scale);
63
extraYAxis.labels().padding(0, 0, 0, 5);
64
65
// setup axis to append '%' symbol to label values
66
extraYAxis.labels().format('{%Value}');
67
68
69
chart.crosshair(true);
70
71
// create line series and set scale for it
72
var lineSeries = chart.line(firstSeriesData);
73
lineSeries.name('Variación interanual');
74
lineSeries.stroke('3 #000 1');
75
extraYAxis.title('Variación interanual');
76
lineSeries.yScale(scale).markers(true);
77
78
79
80
// turn on legend
81
chart.legend().enabled(true).fontSize(12).padding([0, 0, 20, 0]);
82
// set yAxis labels formatter
83
chart.yAxis().labels().format('{%Value}{groupsSeparator: }');
84
85
// set titles for axes
86
//chart.xAxis().title('Variación interanual');
87
chart.yAxis().title('Impuestos directos e indirectos');
88
89
// set interactivity hover
90
chart.interactivity().hoverMode('by-x');
91
92
93
// create third series with mapped data
94
//chart.column(thirdSeriesData);
95
var series;
96
// create second series with mapped data
97
series = chart.column(secondSeriesData);
98
series.name('Impuestos indirectos');
99
100
series = chart.column(thirdSeriesData);
101
series.name('Impuestos directos');
102
103
// set container id for the chart
104
chart.container('container');
105
106
// initiate chart drawing
107
chart.draw();
108
});