Line Chart - Demo

This demo illustrates how some of the parameters of the line chart object could be changed by the user.



Time   2000   2001   2002  
0      
10      
20      
30      
Colour      
 

Source code

All code for the LineChart is written in Jscript, and it relies on four include files. These are included in the package, and you are free to modify them for personal use.

  1. <%@ LANGUAGE = JScript%>
  2. // Include the LineDiagram script library.
  3. <!--#include file="LineDiagram.asp"-->
  4. <%
  5. // Create a new LineDiagram
  6. var diagramObj = new LineDiagram();
  7. diagramObj.CreateBackgroundFromImage(Server.mappath("images/dimacLogo.jpg"));
  8. // Settings for the x-scale
  9. diagramObj.xScale.label = "Time";
  10. diagramObj.xScale.SetPosition(40, 180, 260);
  11. diagramObj.xScale.SetLabelFont("Tahoma", 12, "bold", 0x444444, true, false, 0);
  12. diagramObj.xScale.SetValueFont("Tahoma", 12, "normal", 0x444444, true, false, 0);
  13. diagramObj.xScale.minValue = 0;
  14. diagramObj.xScale.maxValue = 30;
  15. diagramObj.xScale.stepSize = 2;
  16. diagramObj.xScale.lineColor = 0x999999;
  17. diagramObj.xScale.lineSize = 1;
  18. // Settings for the y-scale
  19. diagramObj.yScale.label = "Costs";
  20. diagramObj.yScale.SetPosition(40, 180, 150);
  21. diagramObj.yScale.SetLabelFont("Tahoma", 12, "bold", 0x444444, true, false, 0);
  22. diagramObj.yScale.SetValueFont("Tahoma", 12, 0, 0x444444, true, false, 0);
  23. diagramObj.yScale.minValue = 0;
  24. diagramObj.yScale.maxValue = 10;
  25. diagramObj.yScale.stepSize = 2;
  26. diagramObj.yScale.lineColor = 0x999999;
  27. diagramObj.yScale.lineSize = 1;
  28. // Request color values
  29. var c2000 = Request.Item("c2000").Item;
  30. if (!c2000)
  31. c2000 = new String("#9999ff");
  32. var c2001 = Request.Item("c2001").Item;
  33. if (!c2001)
  34. c2001 = new String("#99ee99");
  35. var c2002 = Request.Item("c2002").Item;
  36. if (!c2002)
  37. c2002 = new String("#dd8888");
  38. var imageobj = Server.CreateObject("w3image.Image");
  39. imageobj.CreateEmptySurface(1,1);
  40. // Create some graphs
  41. var graph1 = new LDGraph();
  42. graph1.label = "2000";
  43. graph1.lineColor = imageobj.CreateColor(c2000.valueOf());
  44. var graph2 = new LDGraph();
  45. graph2.label = "2001";
  46. graph2.lineColor = imageobj.CreateColor(c2001.valueOf()); //0x99ee99;
  47. var graph3 = new LDGraph();
  48. graph3.label = "2002";
  49. graph3.lineColor = imageobj.CreateColor(c2002.valueOf()); //0xdd8888;
  50. // Request values from graph 2000
  51. var q1_2000 = Request.Item("q1_2000").Item;
  52. if (!q1_2000)
  53. q1_2000 = 10;
  54. var q2_2000 = Request.Item("q2_2000").Item;
  55. if (!q2_2000)
  56. q2_2000 = 8;
  57. var q3_2000 = Request.Item("q3_2000").Item;
  58. if (!q3_2000)
  59. q3_2000 = 4;
  60. var q4_2000 = Request.Item("q4_2000").Item;
  61. if (!q4_2000)
  62. q4_2000 = 5;
  63. // Set the values of graph1
  64. graph1.AddPoint(0, parseInt(q1_2000));
  65. graph1.AddPoint(10, parseInt(q2_2000));
  66. graph1.AddPoint(20, parseInt(q3_2000));
  67. graph1.AddPoint(30, parseInt(q4_2000));
  68. // Request values from graph 2001
  69. var q1_2001 = Request.Item("q1_2001").Item;
  70. if (!q1_2001)
  71. q1_2001 = 0;
  72. var q2_2001 = Request.Item("q2_2001").Item;
  73. if (!q2_2001)
  74. q2_2001 = 2;
  75. var q3_2001 = Request.Item("q3_2001").Item;
  76. if (!q3_2001)
  77. q3_2001 = 2;
  78. var q4_2001 = Request.Item("q4_2001").Item;
  79. if (!q4_2001)
  80. q4_2001 = 4;
  81. // Set the values of graph2
  82. graph2.AddPoint(0, parseInt(q1_2001));
  83. graph2.AddPoint(10, parseInt(q2_2001));
  84. graph2.AddPoint(20, parseInt(q3_2001));
  85. graph2.AddPoint(30, parseInt(q4_2001));
  86. // Request values from graph 2002
  87. var q1_2002 = Request.Item("q1_2002").Item;
  88. if (!q1_2002)
  89. q1_2002 = 8;
  90. var q2_2002 = Request.Item("q2_2002").Item;
  91. if (!q2_2002)
  92. q2_2002 = 3;
  93. var q3_2002 = Request.Item("q3_2002").Item;
  94. if (!q3_2002)
  95. q3_2002 = 6;
  96. var q4_2002 = Request.Item("q4_2002").Item;
  97. if (!q4_2002)
  98. q4_2002 = 7;
  99. // Set the values of graph3
  100. graph3.AddPoint(0, parseInt(q1_2002));
  101. graph3.AddPoint(10, parseInt(q2_2002));
  102. graph3.AddPoint(20, parseInt(q3_2002));
  103. graph3.AddPoint(30, parseInt(q4_2002));
  104. // Add the graphs
  105. diagramObj.graphs.push(graph1);
  106. diagramObj.graphs.push(graph2);
  107. diagramObj.graphs.push(graph3);
  108. // Set the value
  109. diagramObj.graphInfo.startXPos = 330;
  110. diagramObj.graphInfo.startYPos = 20;
  111. diagramObj.graphInfo.boxWidth = 15;
  112. diagramObj.graphInfo.boxHeight = 10;
  113. diagramObj.graphInfo.boxSpacing = 5;
  114. diagramObj.graphInfo.lineColor = 0x444444;
  115. diagramObj.graphInfo.SetLabelFont("Tahoma", 12, "normal", 0x444444, true, false);
  116. // Draw the diagram
  117. diagramObj.DrawDiagram();
  118. %>