XML technologies / SVG / Manipulating graphics with external scripts / Using external scripts for manipulation / Inserting the script into the HTML page

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

The HTML page containing the charts also needs a script. Since only Internet Explorer can execute this example anyway, you can use either JavaScript or VBScript. This example uses JavaScript, but can easily be recreated in VBScript because the objects and methods are identical.

Insert the script with the <SCRIPT> tag, just as in the SVG file. Here, however, set its type attribute to "text/javascript".

<html>
  <head>
    <title>Beispiel SVG-Formatierung per XML und JavaScript</title>
    <SCRIPT language="JavaScript1.2" type="text/javascript">
    <!--
      var SVGDiag, SVGDoc, alterText;
      var MaxHoehe=0;
      var MaxBreite=0;
      var legende,reihen,format;
      var farben = new Array();
      var texte = new Array();
      var werte = new Array();
      var xtext="";
      var ytext=""; 
      var xtitel="";
      var ytitel="";
      var hoehetitel="";
      var titelbgcolor="";
      var titelcolor="";

      function INIT(DIAGName)
      {
        ...
      }
      
      function INITDiagramm(DiagObj)
      {
        ...
      }
    // 
     -->
    </SCRIPT>
  </head>
  <body bgcolor="white" onload="INIT('diagramm');INIT('diagramm2')">
  ...

First define some global variables temporarily storing the XML file’s values and formatting. Define them outside a function in the <SCRIPT> tag. The two functions INIT( ) and INITDiagramm( ) in the preceding listing initialize the variables and format the charts. To call the functions for each chart on the page, use the onload attribute of the <BODY> tag and pass the function INIT the name of the chart to process.

   

 

 

 

back to top