Thach Lockevn
Thach Lockevn

Reputation: 1578

How to render multiple AmCharts (version 3) Serial chart on same page?

I need a page with several charts (render multiple aspects of same dataset).

Here is the problem code http://jsfiddle.net/mZ2Gq/227/

var chart1 = AmCharts.makeChart("chart1div", $.extend(true, AMCHART_SERIAL_CONFIG, { "theme": "dark" }) );
var chart2 = AmCharts.makeChart("chart2div", $.extend(true, AMCHART_SERIAL_CONFIG, { "theme": "light" }) );

It only can render the last chart propertly. How can I work-around this issue?

Upvotes: 1

Views: 1898

Answers (1)

gerric
gerric

Reputation: 2297

The problem is that you're using the same configuration object for both charts. This does not work.

You can solve this by using an empty object {} as target in the $.extend method. Just like this:

AmCharts.makeChart("chart", $.extend(true, {}, AMCHART_SERIAL_CONFIG, {theme: "dark"}));

Here's your updated fiddle.

Note: You should avoid using deep merge if not necessary. It slows your code.

Upvotes: 2

Related Questions