Data Compression
Overview
AnyChart Stock component is an SWF file, which is loaded by the browser just as any HTML page with a flash object embedded in it. Since the data to be shown is usually located on the sever, any time you need to show a new data set, you should load it as well.
In the cases when you have really large data sets, while the bandwidth is limited, you can use data compression to save the bandwidth and improve user experience.
AnyChart Stock can accept zlib compressed CSV data sets. A data set can be either a compressed file or a script that outputs a compressed stream.
You can learn more about Zlib at: http://en.wikipedia.org/wiki/Zlib
Sample
In this section we are going to demonstrate how to compress a CSV file named ixic_daily.csv on the server side using PHP and how to use it in AnyChart Stock.
Here is a simple PHP script that compresses the file and then saves it under a different name:
As the result, we get ixic_daily.csv.dat (138 KB) instead of ixic_dialy.csv (438 KB). Quite significant difference!
To use the compressed data in the component, specify it in the data set definition. For that purpose, set the compressed attribute in the <data_set> node to true.
Here is a sample XML for a data set that uses compressed data:
01 |
<?xml version="1.0" encoding="UTF-8"?> |
02 |
< stock xmlns = "http://anychart.com/products/stock/schemas/1.9.0/schema.xsd" > |
The live sample below uses both compressed and uncompressed data; the data and the chart are identical, but if you use the compressed data only, you can both save the bandwidth and speed the things up:
Live Sample: Using Compressed Data
Note: The data set that uses compression should have all the same settings that the data set without compression has: CSV settings, locale, and so on.
Note: You cannot use a compressed data set with the InternalData mode (<data_set source_mode="InternalData">), as the XML cannot contain raw binary data.
Note: You can use compressed files, as shown in the sample above, and scripts that output a zlib-compressed stream. In this case, you simply specify the script's address instead of file's URL; for example, <data_set source_url="http://localhost/getdata.php">.
The preparation and the way you handle compressed data heavily depends on your application; please consider this sample and feature as an opportunity rather than the final solution, for the final solution is highly individual - perhaps you could use data streaming instead of using compression.