HTMLcopy
1
<select id="typeSelect" onchange="switchType()">
2
<option value="area">Area</option>
3
<option value="column">Column</option>
4
<option value="jump-line">Jump Line</option>
5
<option value="line">Line</option>
6
<option value="marker">Marker</option>
7
<option value="spline-area">Spline Area</option>
8
<option value="spline">Spline</option>
9
<option value="step-area">Step Area</option>
10
<option value="step-line">Step Line</option>
11
<option value="stick">Stick</option>
12
</select>
13
<div id="container"></div>
CSScopy
15
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
select {
8
margin: 10px 0 0 10px;
9
}
10
#container {
11
position: absolute;
12
width: 100%;
13
top: 35px;
14
bottom: 0;
15
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// set the data
4
var table = anychart.data.table('x');
5
table.addData(data_us_population());
6
7
// map the data
8
mapping = table.mapAs({x:'x', value:'value'});
9
10
// set the chart type
11
var chart = anychart.stock();
12
13
// set the series type
14
series = chart.plot(0).area(mapping);
15
series.name("Population");
16
17
// format y-axis labels
18
chart.plot(0).yAxis().labels().format("{%value}m");
19
20
// set the chart title
21
chart.title('Switching the Series Type in Stock Charts');
22
23
// create a scroller series with values
24
scrollerSeries = chart.scroller().area(table.mapAs({'value': 'value'}));
25
26
// set the container id
27
chart.container("container");
28
29
// initiate drawing the chart
30
chart.draw();
31
});
32
33
// switch the series type
34
function switchType() {
35
var select = document.getElementById("typeSelect");
36
// switch the type of the main series
37
series.seriesType(select.value);
38
// switch the type of the scroller series
39
scrollerSeries.seriesType(select.value);
40
}
41
42
// create data
43
function data_us_population() {
44
return [
45
{x:'1790-01-01', value:3.929214},
46
{x:'1795-01-01', value:4.390561},
47
{x:'1800-01-01', value:5.236631},
48
{x:'1805-01-01', value:5.989289},
49
{x:'1810-01-01', value:7.239881},
50
{x:'1815-01-01', value:8.722382},
51
{x:'1820-01-01', value:9.638453},
52
{x:'1825-01-01', value:10.923857},
53
{x:'1830-01-01', value:12.866020},
54
{x:'1835-01-01', value:15.454230},
55
{x:'1840-01-01', value:17.069453},
56
{x:'1845-01-01', value:19.234543},
57
{x:'1850-01-01', value:23.191876},
58
{x:'1855-01-01', value:28.347121},
59
{x:'1860-01-01', value:31.443321},
60
{x:'1865-01-01', value:34.098412},
61
{x:'1870-01-01', value:38.558371},
62
{x:'1875-01-01', value:44.728322},
63
{x:'1880-01-01', value:49.371340},
64
{x:'1885-01-01', value:53.989443},
65
{x:'1890-01-01', value:62.979766},
66
{x:'1895-01-01', value:71.883243},
67
{x:'1900-01-01', value:76.212168},
68
{x:'1905-01-01', value:85.023411},
69
{x:'1910-01-01', value:92.228496},
70
{x:'1915-01-01', value:100.378232},
71
{x:'1920-01-01', value:106.021537},
72
{x:'1925-01-01', value:118.323005},
73
{x:'1930-01-01', value:123.202624},
74
{x:'1935-01-01', value:126.232034},
75
{x:'1940-01-01', value:132.164569},
76
{x:'1945-01-01', value:144.773641},
77
{x:'1950-01-01', value:151.325798},
78
{x:'1955-01-01', value:160.460555},
79
{x:'1960-01-01', value:179.323175},
80
{x:'1965-01-01', value:188.232951},
81
{x:'1970-01-01', value:203.211926},
82
{x:'1975-01-01', value:215.789873},
83
{x:'1980-01-01', value:226.545805},
84
{x:'1985-01-01', value:239.905274},
85
{x:'1990-01-01', value:248.709873},
86
{x:'1995-01-01', value:272.119084},
87
{x:'2000-01-01', value:281.421906},
88
{x:'2005-01-01', value:299.456285},
89
{x:'2010-01-01', value:308.745538},
90
{x:'2015-01-01', value:318.914629}
91
]}