Listing 1: Typical DataWindow XML export

<chart_data>
     <row>
          <year>2002</year>
          <sales>15</sales>
     </row>
     <row>
          <year>2003</year>
          <sales>27</sales>
     </row>
     <row>
          <year>2004</year>
          <sales>45</sales>
     </row>
     <row>
          <year>2005</year>
          <sales>60</sales>
     </row>
</chart_data>

Listing 2: The XML the library is expecting

<chart_data>
<row>
	<null/>
	<string>2002</string>
	<string>2003</string>
	<string>2004</string>
	<string>2005</string>
</row>
<row>
	<string>Sales</string>
	<number>15</number>
	<number>27</number>
	<number>45</number>
	<number>60</number>
</row>
</chart_data>

Listing 3 - Generating the XML for the library

integer 	li_file
long		ll_pos
string	ls_labels, ls_values, ls_chart, ls_series_colors, ls_series_explode, ls_data
datastore	lds_data

//Accept any pending changes to the data or chart format
dw_data.AcceptText()
dw_chartoptions.AcceptText()

//Create a datastore
lds_data = CREATE datastore
lds_data.DataObject = dw_data.DataObject
//Reset the datawindow, because I've got data embedded in it
lds_data.Reset()
//Copy the current chart data into it
dw_data.RowsCopy ( 1, dw_data.RowCount(), Primary!, lds_data, 1, Primary! )

//Insert one dummy row at the beginning
lds_data.InsertRow ( 1 )

//Export the XML for the data
lds_data.Object.DataWindow.Export.XML.UseTemplate='labels'
ls_labels = lds_data.Object.DataWindow.Data.XML

lds_data.Object.DataWindow.Export.XML.UseTemplate='values'
ls_values = lds_data.Object.DataWindow.Data.XML

//Delete the dummy row
lds_data.DeleteRow ( 1 )

//Export the XML for the series
lds_data.Object.DataWindow.Export.XML.UseTemplate='series_color'
ls_series_colors = lds_data.Object.DataWindow.Data.XML

lds_data.Object.DataWindow.Export.XML.UseTemplate='series_explode'
ls_series_explode = lds_data.Object.DataWindow.Data.XML

//Destroy the datastore
Destroy lds_data

//Export the XML for the chart options
ls_chart = dw_chartoptions.Object.DataWindow.Data.XML

//Put together the chart data and add it to the chart XML
ls_data = '<chart_data>~r~n' + ls_labels + ls_values + '</chart_data>'
ll_pos = Pos ( ls_chart, '<chart_data/>' )
ls_chart = Replace ( ls_chart, ll_pos, 13, ls_data )

//Add the series XML options
ll_pos = Pos ( ls_chart, '<series_color/>' )
ls_chart = Replace ( ls_chart, ll_pos, 15, Left ( ls_series_colors, Len ( ls_series_colors ) - 2 ) )
ll_pos = Pos ( ls_chart, '<series_explode/>' )
ls_chart = Replace ( ls_chart, ll_pos, 17, Left ( ls_series_explode, Len ( ls_series_explode ) - 2 ) )

//Write the file out
li_file = FileOpen ("sample.xml", TextMode!, Write!, LockWrite!, Replace!)
FileWriteEx (li_file, ls_chart )
FileClose ( li_file )

Listing 4 Displaying the resulting chart

string	ls_directory, ls_movie

ls_directory = GetCurrentDirectory()
ls_movie = ls_directory + "\charts.swf?library_path=charts_library&xml_source=sample.xml"

ole_shockwave.Object.Movie = ls_movie
ole_shockwave.Object.Play()