11.07.2015 Views

AJAX and PHP

AJAX and PHP

AJAX and PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>AJAX</strong> Real-Time Charting with SVG0.0...... more text nodes here that draw horizontal <strong>and</strong> vertical unit numbers......... more circle nodes here that draw filled blue circles for chart nodes...Have a closer look at this code snippet to identify all the chart elements. The SVG format supportsthe notion of element groups, which are elements grouped under a element. In temp.svg wehave two groups: the first group contains all the charts' elements, translating them by (50, 50)pixels, while the second element group is a child of the first group, <strong>and</strong> it contains the chart'saxis lines <strong>and</strong> numbers.SVG knows how to h<strong>and</strong>le many element types, which can also be animated (yes, SVG is verypowerful). In our example, we make use of some of the very basic ones: path (to draw the axislines <strong>and</strong> chart lines), text (to draw the axis numbers, <strong>and</strong> to dynamically display chart nodecoordinates when the mouse cursor hovers over them—this latter feature isn't included in the codesnippet), <strong>and</strong> circle (to draw the blue dots on the chart that represent the chart nodes).You can find documentation for these elements at:• http://www.w3schools.com/svg/svg_path.asp• http://www.w3schools.com/svg/svg_circle.asp• http://www.w3schools.com/svg/svg_text.aspThe paths are described by a path definition. The complete code for the path element that drawsthe chart lines you can see in Figure 7.1 looks like this:A detail that was stripped from the code snippet was the mouseover <strong>and</strong> mouseout events of thechart node circles. In our code, the mouseover event (which fires when you move the mousepointer over a node) will call a JavaScript function that displays a text above the node specifyingits coordinates. The mouseout event makes that text disappear. You can see this feature in actionin Figure 7.2, which displays the SVG chart application in action.192

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!