Two charts as one chart object
by jlbriggs
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="width:500px;height:375px;margin:1.5em 1em;"></div>
<script>
var d = new Date();
var pointStart = d.getTime();
Highcharts.setOptions({
global: {
useUTC:false
},
colors: [
'rgba( 0, 154, 253, 0.9 )', //bright blue
'rgba( 253, 99, 0, 0.9 )', //bright orange
'rgba( 40, 40, 56, 0.9 )', //dark
'rgba( 253, 0, 154, 0.9 )', //bright pink
'rgba( 154, 253, 0, 0.9 )', //bright green
'rgba( 145, 44, 138, 0.9 )', //mid purple
'rgba( 45, 47, 238, 0.9 )', //mid blue
'rgba( 177, 69, 0, 0.9 )', //dark orange
'rgba( 140, 140, 156, 0.9 )', //mid
'rgba( 238, 46, 47, 0.9 )', //mid red
'rgba( 44, 145, 51, 0.9 )', //mid green
'rgba( 103, 16, 192, 0.9 )' //dark purple
],
chart: {
alignTicks:false,
type:'',
//borderRadius:10,
//borderWidth:1,
//borderColor:'rgba(156,156,156,.25)',
//backgroundColor:'rgba(204,204,204,.25)',
//plotBackgroundColor:'rgba(255,255,255,1)',
style: {
fontFamily: 'Abel,serif'
}
},
title: {
text:'Test Chart Title',
align:'left',
margin:10,
x: 50,
style: {
fontWeight:'bold',
color:'rgba(0,0,0,.9)'
}
},
subtitle: {
text:'Test Chart Subtitle',
align:'left',
x: 52,
},
legend: { enabled: true },
plotOptions: {
area: {
lineWidth:1,
marker: {
enabled:false,
symbol:'circle',
radius:4
}
},
arearange: {
lineWidth:1
},
areaspline: {
...
CSS
@import url(https://fonts.googleapis.com/css?family=Changa+One|Loved+by+the+King|Fredericka+the+Great|Droid+Serif:400,700,400italic|Abel|Oswald:400,300,700);
body {
font-family:Abel, Calibri, Helvetica, sans-serif;
font-size:95%;
}
JavaScript
var chart;
$(function() {
$('#container').highcharts({
chart : { margin:[60,25,90,90], type: 'area' },
title : { },
subtitle : { },
legend : { enabled : true },
tooltip : { },
plotOptions : {
series : {
pointStart : pointStart,
pointInterval : 3600 * 1000,
}
},
xAxis : [{
type: 'datetime',
offset: -120
},{
type: 'datetime',
}],
yAxis : [{
title: { text: 'Y Axis 0' },
height:100
},{
title: { text: 'Y Axis 1' },
offset: 0,
top: 200,
height:100
}]
});
chart = $('#container').highcharts();
chart.addSeries({
xAxis: 0,
yAxis: 0,
data: randomData(50)
});
chart.addSeries({
xAxis: 1,
yAxis: 1,
data: randomData(150, true, 10)
});
})