vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.7 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  5. <meta content="utf-8" http-equiv="encoding">
  6. <title>Graph2d | Basic Example</title>
  7. <style type="text/css">
  8. body, html {
  9. font-family: sans-serif;
  10. }
  11. .red {
  12. fill:red;
  13. }
  14. </style>
  15. <script src="../../dist/vis.js"></script>
  16. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  17. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
  18. <body>
  19. <h2>Graph2d | Label Example</h2>
  20. <div style="width:700px; font-size:14px; text-align: justify;">
  21. This example shows the how to add a label to each point in Graph2d. Each item can have a label object which contains the content and CSS class.In addition, xOffset and yOffset will adjust the location of the label relative to the point being labelled.
  22. <br /><br />
  23. </div>
  24. <br />
  25. <div id="visualization"></div>
  26. <script type="text/javascript">
  27. var container = document.getElementById('visualization');
  28. var label1 = {
  29. content: "Label 1 (with offset)",
  30. xOffset: 20,
  31. yOffset: 20
  32. }
  33. var label2 = {
  34. content: "Label 2",
  35. className: "red"
  36. }
  37. var label3 = {
  38. content: "Label 3"
  39. }
  40. var items = [
  41. {group: 1, x: '2014-06-11', y: 10, label: label1},
  42. {group: 1, x: '2014-06-12', y: 25, label: label2},
  43. {group: 1, x: '2014-06-13', y: 30},
  44. {group: 1, x: '2014-06-14', y: 10},
  45. {group: 1, x: '2014-06-15', y: 15, label: label3},
  46. {group: 1, x: '2014-06-16', y: 30},
  47. {group: 2, x: '2014-06-17', y: 10, label:label1},
  48. {group: 2, x: '2014-06-18', y: 25, label:label2},
  49. {group: 2, x: '2014-06-19', y: 30},
  50. {group: 2, x: '2014-06-20', y: 10},
  51. {group: 2, x: '2014-06-21', y: 15, label: label3},
  52. {group: 2, x: '2014-06-22', y: 30},
  53. {group: 3, x: '2014-06-23', y: 10, label:label1},
  54. {group: 3, x: '2014-06-24', y: 25, label:label2},
  55. {group: 3, x: '2014-06-25', y: 30},
  56. {group: 3, x: '2014-06-26', y: 10},
  57. {group: 3, x: '2014-06-27', y: 15, label: label3},
  58. {group: 3, x: '2014-06-28', y: 30}
  59. ];
  60. var groups = new vis.DataSet();
  61. groups.add(
  62. {
  63. id: 1,
  64. content: "Only draw items with labels. Make the data point bigger and a square.",
  65. options: {
  66. drawPoints: function group1Renderer(item, group, grap2d) {
  67. if (item.label == null) {
  68. return false;
  69. }
  70. return {
  71. style: 'square',
  72. size: 15
  73. };
  74. }
  75. }
  76. }
  77. );
  78. groups.add(
  79. {
  80. id: 2,
  81. content: "Draw according to the Graph2d callback, but make it every datapoint square one.",
  82. options: {
  83. drawPoints: {
  84. style: 'square'
  85. }
  86. }
  87. }
  88. );
  89. groups.add(
  90. {
  91. id: 3,
  92. content: "I want to render datapoints with no labels. Screw the graph2d options. Except the style/size should be according to the graph2d option.",
  93. options: {
  94. drawPoints: function(item, group, grap2d) {
  95. return item.label == null;
  96. }
  97. }
  98. }
  99. );
  100. var dataset = new vis.DataSet(items);
  101. var options = {
  102. start: '2014-06-10',
  103. end: '2014-06-29',
  104. style: 'bar',
  105. drawPoints: {
  106. onRender: function(item, group, grap2d) {
  107. return item.label != null;
  108. },
  109. style: 'circle'
  110. }
  111. };
  112. var graph2d = new vis.Graph2d(container, dataset, groups, options);
  113. </script>
  114. </body>
  115. </html>