Resizing chart for print

Type tutorial

Usually browsers use different resolution when printing web pages. If you have charts that are wider than ~600-700 pixels, they will print as cropped. To overcome this, use the following code to make the charts redraw using new dimensions before the page is printed: (function() { var beforePrint = function() { for(var i = 0; […]

Adding multiple value axis to a Stock Charts panel

Type tutorial

In Stock chart, each StockPanel is an instance of AmSerialChart. So you can add ValueAxis objects to it like you would normally add to a regular chart. Each StockGraph is an instance os AmGraph so it has valueAxis property. So adding multiple value axes to a stock panel is just like adding them to a […]

Putting a legend outside the chart area

Type tutorial

Chart legend is a great visual tool that makes charts event more usable and easy to comprehend. However, sometimes it’s size gets unpredictable. If there are a lot of items in the legend, the actual chart gets shrunk in order to accommodate space for the legend. This may lead to unattractive situations like this: Ain’t […]

Make the pie chart to take the whole space of the container

Type tutorial

In order for the pie to take the whole width/height of the container you will need to: 1) Disable callouts / labels; 2) Set all margins to zero; 3) Disable slice pullout functionality. Like this: chart.labelsEnabled = false; chart.autoMargins = false; chart.marginTop = 0; chart.marginBottom = 0; chart.marginLeft = 0; chart.marginRight = 0; chart.pullOutRadius = […]

Moving average indicators for Stock Chart

Type tutorial

Normally JavaScript Stock Chart does not support automatically-calculated “moving average” graphs or other indicators. However, it’s quite easy to add such functionality yourself. Here’s a code for “moving average”: (it should be included after amstoock.js) // MOVING AVERAGE PLUGIN FOR JAVASCRIPT STOCK CHARTS FROM AMCHARTS // AmCharts.averageGraphs = 0; AmCharts.addMovingAverage = function (dataSet, panel, field) […]

Replacing axis labels with arbitrary text

Type tutorial

Although you can format value axis labels like duration, add unit to the left or right of the value, you might need something more – for example, to replace numeric values of value axis with some strings or add some text to category axis labels. ValueAxis has labelFunction property for that. If you set some function […]

Non-English months / weekdays

Type tutorial

Month/weekday names can be set on all charts using the following properties of AmCharts class: monthNames, shortMonthNames, dayNames and shortDayNames. So, to translate month names to German, you should set: AmCharts.monthNames = [   ‘Januar’,   ‘Februar’,   ‘März’,   ‘April’,   ‘Mai’,   ‘Juni’,   ‘Juli’,   ‘August’,   ‘September’,   ‘Oktober’,   ‘November’,   ‘Dezember’];

Disabling cursor / scrollbar in Stock Chart

Type tutorial

To hide the chart cursor in JavaScript Stock Chart just simply set enabled to false in ChartCursorSettings: chart.chartCursorSettings.enabled = false; To hide the scrollbar in JavaScript Stock Chart just simply set enabled to false in ChartScrollbarSettings: chart.chartScrollbarSettings.enabled = false;  

Pages with base-href (i.e. AngularJS)

Type tutorial

If your web page is using the <base href> header make sure you include the following line before initializing the chart/map: AmCharts.baseHref = true; It will ensure the common SVG problems related to base href are avoided.

Multi-segmented line graph

Type tutorial

Some time ago, in order to have multi-segmented line chart (the one where line color or fill color changes at some point) you had to add several different graphs and this wasn’t very straight forward task. However since v3 we added lineColorField, fillColorsField and dashLengthField properties to AmGraph and now you can do it very […]