Back to amCharts.com

Data inside HTML

Instead of loading data from a file, you can pass it to the chart directly from your HTML page. The data gets embedded in the HTML code snippet that you use to add the chart to the page.

Open your web page file in Notepad and locate the code snippet. Find the following line:

so.addVariable("chart_data", "");

By default this line has double backslashes in front of it, which means that it is ignored by the software. If you remove the backslashes, the software will look for data in that line, not in the data file.

The data goes inside the last pair of quotation marks. It must be in a single string - without line breaks!

If you are using XML, the data can simply be copied with all extra spaces and line breaks removed:

so.addVariable("chart_data", "<chart><series><value xid='0'>2000</value><value xid='1'>2001</value><value xid='2'>2002</value></series><graphs><graph gid='0' title='First title'><value xid='0'>6</value><value xid='1'>36</value><value xid='2'>34</value></graph></graphs></chart>");

Important notice:

If you include data inside the HTML, check that your data does not have XML attributes, for example: <graph gid="1">. If you have this or any other attributes inside your data, replace all double quotes with single quotes: <graph gid='1'>. If you don't do this, you will receive a JavaScript error, because your full data strings are already inside double qoutes.

If you are using CSV, the data must be copied with \n instead of each line break:

so.addVariable("chart_data", "First;50\nSecond;80\nThird;90");

Remember to set the <data_type> property in the settings to the correct value!

Back to top