amCharts Documentation
Search:     Advanced search
Browse by category:

Data

Views: 4374

Data

To display a custom chart, amPie will need to get your data in a suitable form. There are two formats you can use: CSV and XML.

  • CSV (Comma-Separated Values) is a very simple data format. You can easily build this by hand if you don't have too much information. Almost all programs that keep lists of data (such as MS Excel) can export them into CSV. You can edit a CSV file manually in your text editor.
  • XML (Extensible Markup Language) is a more complicated data format. It can have all kinds of extra information, telling the software how to handle the data. XML is harder to edit with Notepad - it is better to use a more functional program like PSPad for Windows or Smultron for Mac OS X.

CSV data is similar to a very simple Excel table. Rows are separated by line breaks (each new table row is a new text row in the file). Columns are separated by a special character - usually a comma ',' or a semicolon ';'. This character is called a separator.


Adding the Data - XML

If you are using the default file and folder names, the data goes into the file ampie_data.xml, which is located in the ampie directory. You will see the following code:

<pie>
  <!--
  <message bg_color="#CCBB00" text_color="#FFFFFF">
    <![CDATA[You can broadcast any message to chart from data XML file]]>
  </message>
  -->
  <slice title="Twice a day" pull_out="true">358</slice>
  <slice title="Once a day">258</slice>
  <slice title="Once a week">154</slice>
  <slice title="Never" url="http://www.interactivemaps.org" description="Click on the slice to find more information" alpha="50">114</slice>
</pie>

The important rows are the ones starting with <slice. These hold the individual parts of your pie or donut chart - the slices. There are two types of data you can store here:

  • Value - the number behind the slice. The software will automatically add up all the slice values, calculate the percentage of each value from the total, and adjust the slice sizes accordingly.
  • Parameters - these provide additional information about the slice. They always have the format parameter="information".
    • title - the name of the slice. 
    • pull_out - if this is set to "true", the slice will be pulled out when the chart is first displayed.
    • color - the color of the slice. You must use hexadecimal HTML color codes. If you do not provide the color for a slice, a set of default colors will be used.
    • url - when the viewer clicks on the slice, the URL specified here will open in the browser. This is disabled while you are working with files on your hard drive - it will start working when you upload the files to your web server!
    • description - text that will appear in the balloon when the viewer drags the mouse over the slice. You can use some HTML tags here, but you will have to replace < with &lt; and > with &gt;.
    • alpha - opacity of the slice, in percent. If set to 0, the slice is invisible and unclickable. You can use this parameter to create partial pies. Tip: you can use partial pies with URL-enabled slices to create unusual Flash menus for your website!  
    • label_radius - you can set data label's distance from a pie for each slice individualy.

Change the slice parameters and values to reflect your data. You can create as many slices as you like, as long as they are all in the format <slice parameter="information">value</slice>, and are placed sequentially in the file.

The sequential order of the slices in the file is the same as their order on the chart, clockwise from the top.


Adding the Data - CSV

If you are using CSV data, you must tell the software to look for that format.

  1. First, open your page's file and find the code snippet. Find the following line:

so.addVariable("data_file", escape("ampie/ampie_data.xml"));

Change ampie_data.xml to ampie_data.txt, and save/upload the file.

  1. Open the settings file (ampie/ampie_settings.xml by default) in Notepad, and find the following line:

<data_type>xml</data_type>

Replace xml with csv and save/upload the file.

If you are using the default file and folder names, the data goes into the file ampie_data.txt, which is located in the ampie directory.

The CSV file is actually plain text. Each slice is on a new row. The parameters and value are separated by a special character. By default, this is the semicolon, but you can change it to a different character using the chart settings. The slice information is in the following order: title;value;pull_out;color;url;description;alpha;label_radius

  • title - the name of the slice.
  • pull_out - if this is set to "true", the slice will be pulled out when the chart is first displayed.
  • color - the color of the slice. You must use hexadecimal HTML color codes.
  • url - when the viewer clicks on the slice, the URL specified here will open in the browser. This is disabled while you are working with files on your hard drive - it will start working when you upload the files!
  • description - text that will appear in the balloon when the viewer drags the mouse over the slice. You can use some HTML tags here. Make sure you don't use the CSV separator character in the description!
  • alpha - opacity of the slice, in percent. If set to 0, the slice is invisible and unclickable. You can use this parameter to create partial pies. Tip: you can use partial pies with URL-enabled slices to create unusual Flash menus for your website!
  • label_radius - you can set data label's distance from a pie for each slice individualy.

If you are only using the first two or more, you don't have to specify the rest. If you are skipping some parameters, but using a later one, you must use a semicolon for each skipped parameter. Check the example ampie_data.txt file to see how this works. 

The sequential order of the slices in the file is the same as their order on the chart, clockwise from the top.


External Data Files

You can use any data file name and file type you want. The data file does not have to be an XML or plaintext file. It can be PHP, ASP, or any other format. As long as you can open the file's URL in your browser and get XML or CSV data in return, the software will work. You can also pass parameters to the data file in the URL.

To use a data file different from the default, open your web page file in Notepad. Find the code snippet for the chart. Find the following line:

so.addVariable("data_file", escape("ampie/ampie_data.xml"));

Replace ampie/ampie_data.xml with the full path to your data file. We recommend that you use relative paths, like in the example above - full paths can cause conflicts with the Flash Player's security settings.

Loading data from a different domain or from a secure server (https://)

To load data from a different domain, or from a server whose URL starts with https://, you need to create a cross domain policy file and upload it to the server where your data is. More ways to solve this problem can be found here. 

There is another easy way to load data from secure server (starting with https://) - all you need to do is to add this header to your php file:

header("Pragma: cache");

Others in this Category
document Dynamic Data
document Data in the HTML