Now we come to the most interesting part of our tutorial - making the chart dynamic. The first dynamic feature we will add is a possibility to switch between 'Profits' and 'Losses' data.
To provide the possibility we will:
"index.html" file
var form = layout.cells("a").attachForm();
"data/form.xml" file
<?xml version="1.0"?>
<items>
<item type="settings" position="label-right" offsetLeft="20"
labelWidth="150"/>
<item type="block" width="230" offsetLeft="0">
<item type="label" label="Show report for:" offsetLeft="0"/>
<item type="radio" name="report_type" value="profits" label="Profits"
checked="true" />
<item type="radio" name="report_type" value="losses" label="Losses"/>
</item>
</items>
"index.html" file
var form = layout.cells("a").attachForm();
form.loadStruct("data/form.xml");
'index.html' file
form.attachEvent("onChange", function (){
var formValues = form.getFormData(); //gets values of the checked controls
//variable 'field' specifies the data field that will be displayed in chart
var field=(formValues.report_type == "profits"?"data2":"data3");
chart.clearAll(); //clears the chart from data
chart.define("value","#"+field+"#");//sets new data property for the Y-Axis
chart.parse(grid,"dhtmlxgrid"); //loads data from the grid
chart.render(); //renders the chart on the page
});