Updating Chart Data on Server
The drag-node chart allows you to update data in real-time and submit the modified data to your scripts for further processing.
The drag-node chart offers you two methods to update chart data on the server:
-
Submit the updated data from the chart to your server-side script (as form elements) in XML format.
-
Submit the updated data as XML/array to client-side JavaScript functions. These functions can now handle the data in the way they want to.
In this section, you will be shown how you can update chart data using server-side scripts.
Setting the Form
To enable submission of data to server-side script, you first need to make sure that the Submit button is not hidden on your form.
To show the Submit button, you can use the following code snippet:
This adds a submit button to your chart as shown below:
Given below is a brief description of the attributes used to show/hide and define the form properties for the Submit button:
Attribute Name | Description |
---|---|
|
It is used to specify whether the Submit button will be rendered on the chart. Setting this attribute to |
|
It is used to specify the URL of the server-side script to which you want to submit the updated data. You can specify the relative or the absolute path. The |
|
It is used to specify the method - |
|
It is used to specify the target page where the response received after submitting form data will be rendered. This attribute takes the following two values: |
|
It is used to specify the text label for the Submit button. By default, the label is Submit. |
|
It is used to specify the hex code of the color for the Submit button. |
|
It is used to specify the width, in pixels, of the Submit button. |
|
It is used to specify the hex code of the border color for the Submit button. |
|
It is used to specify the hex code of the background color for the Submit button. |
The code snippet below shows how the server-side PHP script is used to submit data:
<?php
//File to write
$filename = 'xml/dragNodeData.xml';
//Requested data
$content = $_REQUEST['strXML'];
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in write mode.
// The file pointer is at the bottom of the file hence
// that's where $content will go when we fwrite() it.
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $content to our opened file.
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($content) to file ($filename)";
//Close the file
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>