Stock Events
Our Stock chart can display different kind of annotations on the graph or on the axis. These annotations or stock events as we call them can mark important news or events connected to the security or bond. As you see, there is a wide variety of event types – they can look like a flag or sign or pin and have a letter inside or even contain more text. When user rolls-over the event, you can show a more detailed description or register this event and display some information outside the chart. The events are nicely stacked one on another if there is more than one for the same date.
Chart Scrollbar with a graph inside
In the bottom (it can also be on the top) of the chart you have a chart scrollbar which can be used to zoom-in or zoom-out the chart. This scrollbar can be just a simple one or have a graph inside it to show a rough view of how data changed over the whole period of the data available.
Demo source
<!-- Styles -->
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<!-- Resources -->
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/amstock.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<!-- Chart code -->
<script>
var chartData = [];
generateChartData();
function generateChartData() {
var firstDate = new Date( 2012, 0, 1 );
firstDate.setDate( firstDate.getDate() - 500 );
firstDate.setHours( 0, 0, 0, 0 );
for ( var i = 0; i < 500; i++ ) {
var newDate = new Date( firstDate );
newDate.setDate( newDate.getDate() + i );
var a = Math.round( Math.random() * ( 40 + i ) ) + 100 + i;
var b = Math.round( Math.random() * 100000000 );
chartData.push( {
"date": newDate,
"value": a,
"volume": b
} );
}
}
var chart = AmCharts.makeChart( "chartdiv", {
"type": "stock",
"theme": "none",
"dataSets": [ {
"color": "#b0de09",
"fieldMappings": [ {
"fromField": "value",
"toField": "value"
}, {
"fromField": "volume",
"toField": "volume"
} ],
"dataProvider": chartData,
"categoryField": "date",
// EVENTS
"stockEvents": [ {
"date": new Date( 2010, 8, 19 ),
"type": "sign",
"backgroundColor": "#85CDE6",
"graph": "g1",
"text": "S",
"description": "This is description of an event"
}, {
"date": new Date( 2010, 10, 19 ),
"type": "flag",
"backgroundColor": "#FFFFFF",
"backgroundAlpha": 0.5,
"graph": "g1",
"text": "F",
"description": "Some longerntext can alson be added"
}, {
"date": new Date( 2010, 11, 10 ),
"showOnAxis": true,
"backgroundColor": "#85CDE6",
"type": "pin",
"text": "X",
"graph": "g1",
"description": "This is description of an event"
}, {
"date": new Date( 2010, 11, 26 ),
"showOnAxis": true,
"backgroundColor": "#85CDE6",
"type": "pin",
"text": "Z",
"graph": "g1",
"description": "This is description of an event"
}, {
"date": new Date( 2011, 0, 3 ),
"type": "sign",
"backgroundColor": "#85CDE6",
"graph": "g1",
"text": "U",
"description": "This is description of an event"
}, {
"date": new Date( 2011, 1, 6 ),
"type": "sign",
"graph": "g1",
"text": "D",
"description": "This is description of an event"
}, {
"date": new Date( 2011, 3, 5 ),
"type": "sign",
"graph": "g1",
"text": "L",
"description": "This is description of an event"
}, {
"date": new Date( 2011, 3, 5 ),
"type": "sign",
"graph": "g1",
"text": "R",
"description": "This is description of an event"
}, {
"date": new Date( 2011, 5, 15 ),
"type": "arrowUp",
"backgroundColor": "#00CC00",
"graph": "g1",
"description": "This is description of an event"
}, {
"date": new Date( 2011, 6, 25 ),
"type": "arrowDown",
"backgroundColor": "#CC0000",
"graph": "g1",
"description": "This is description of an event"
}, {
"date": new Date( 2011, 8, 1 ),
"type": "text",
"graph": "g1",
"text": "Longer text cannalso be displayed",
"description": "This is description of an event"
} ]
} ],
"panels": [ {
"title": "Value",
"stockGraphs": [ {
"id": "g1",
"valueField": "value"
} ],
"stockLegend": {
"valueTextRegular": " ",
"markerType": "none"
}
} ],
"chartScrollbarSettings": {
"graph": "g1"
},
"chartCursorSettings": {
"valueBalloonsEnabled": true,
"graphBulletSize": 1,
"valueLineBalloonEnabled": true,
"valueLineEnabled": true,
"valueLineAlpha": 0.5
},
"periodSelector": {
"periods": [ {
"period": "DD",
"count": 10,
"label": "10 days"
}, {
"period": "MM",
"count": 1,
"label": "1 month"
}, {
"period": "YYYY",
"count": 1,
"label": "1 year"
}, {
"period": "YTD",
"label": "YTD"
}, {
"period": "MAX",
"label": "MAX"
} ]
},
"panelsSettings": {
"usePrefixes": true
},
"export": {
"enabled": true
}
} );
</script>
<!-- HTML -->
<div id="chartdiv"></div>