mike chambers | about

Passing multiple Data Sources through a single Data Source

Generator can connect to multiple sources to retrieve its data. However, if you have multi objects within your template, and each has its own data source, then Generator may have to make several requests for its data. Depending on the source and type of data, this can have a significant impact on Generator’s performance.

However, it is possible to retrieve multiple data sources through one request. However, in order for this to work, Generator needs to be able to connect to some form of middle ware, which will create the data source.

Basically, by using the Generator Environment Variables button in the name, value format, you can specify multiple data sources.

For example, lets say that we have a template that contains a pie and a line chart, each of which has their own data source. Instead of having Generator connect to each data source separately, we will have it make a single request to a middle ware page (such as ASP, JSP, PHP, Cold Fusion or a Java Servlet). The middle ware will then collect the data for the entire template and create a single data source containing the data sources for the pie and line chart.

  1. Set the Environment Variables button to point to your middle ware that will create the data source. Make sure that the Name / Value format button is selected.

  2. Create you middle ware. Lets assume that the data for both charts comes from a data base. The middle ware will make two connections to the data base, and create two column data sources from the results. It will then store each data source in a variable (lets say lineData, and pieData).

  3. Once the middle ware has created the two separate column data sources, it will then create a Name / Value data source with two variables, pieData, and lineData. The values of these two variables will be the column data sources that we created in step two.

  4. Make sure to wrap the values in the Name / Value data source in double quotes, and escape any characters that need to be escaped for Generator.

  5. Finally send the Name / Value data source, which contains the two column data sources back to Generator.

  6. In you Generator template, your pie chart’s data source should point to #{pieData} and the line chart should point to #{lineData}. (The # tells Generator that this variable contains the actual data source and not a pointer to something that contains the data source such as a text file).

  7. You have now retrieved two separate data sources through one request / data source.

Here is an example of what the data source might look like.

name, value

pieData, "value, label, color\n\"4\",\"Basic Charts\",\"#FF0000\"\n\"1\",
\"Plot\",\"#00FF00\"\n\"2\",\"List\",\"#0000FF\"\n\"2\",\"Table\",
\"#FFFF00\"\n\"1\",\"Ticker\",\"#00FFFF\"\n\"1\",\"Scrolling List\",
\"#FF00FF\"\n\"2\",\"Custom Object\",\"#006633\"\n\"1\",\"Flash Movie\",
\"#FF9900\"\n\"1\",\"Pie Chart\",\"#993366\"\n\"1\",\"Insert JPEG\",
\"#FFFFCC\"\n\"1\",\"Insert PNG\",\"#FF0000\"\n\"1\",\"Radio Button\",
\"#00FF00\"\n\"2\",\"Multipage List\",\"#0000FF\"\n"

lineData, "value, hlabel, color\n\"4\",\"Basic Charts\",\"#FF0000\"\n\"1\",
\"Plot\",\"#00FF00\"\n\"2\",\"List\",\"#0000FF\"\n\"2\",\"Table\",
\"#FFFF00\"\n\"1\",\"Ticker\",\"#00FFFF\"\n\"1\",\"Scrolling List\",
\"#FF00FF\"\n\"2\",\"Custom Object\",\"#006633\"\n\"1\",\"Flash Movie\",
\"#FF9900\"\n\"1\",\"Pie Chart\",\"#993366\"\n\"1\",\"Insert JPEG\",
\"#FFFFCC\"\n\"1\",\"Insert PNG\",\"#FF0000\"\n\"1\",\"Radio Button\",
\"#00FF00\"\n\"2\",\"Multipage List\",\"#0000FF\"\n"

Note that there are line returns added above to format for this post, but the data for each entry should all be contained on a single line.

It looks confusing, but each variable basically contains an entire column data source on one line, wrapped in double quotes, with all of its data escaped for Generator.

If you data does not seem to be getting to Generator, only only part of it appears to be available, then make sure that you have wrapped the column data sources in double quotes and escaped all of the Generator special characters within the data. This includes double quotes and line returns i.e. (\n should be \n).

There is also a technote that discusses this:

http://www.macromedia.com/support/generator/ts/documents/multi_data.htm

Tags:
twitter github flickr behance