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.

87 lines
2.7 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <title>Shows how different settings and styles can be mixed in one canvas</title>
  4. <style>
  5. .chart-style {
  6. width: 600px;
  7. height: 340px;
  8. margin-bottom: 15px;
  9. }
  10. .text-block {
  11. margin-bottom: 15px;
  12. }
  13. </style>
  14. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  15. <script type="text/javascript" src="https://cdn.rawgit.com/flot/flot/v0.8.3/jquery.flot.js"></script>
  16. <script type="text/javascript" src="https://rawgit.com/MichaelZinsmaier/CurvedLines/master/curvedLines.js"></script>
  17. <script type="text/javascript">
  18. $(function() {
  19. //some random data
  20. var d1 = []; var last = 0;
  21. for (var i = 0; i <= 40; i += (2 + parseInt(Math.random() * 5))) {
  22. last = last + ((Math.random() * 3) - 1.5)
  23. d1.push([i, parseInt(last)]);
  24. }
  25. var d2 = [];
  26. for (var i = 2; i <= $(d1).get(-1)[0]; i += (2 + parseInt(Math.random() * 5))) {
  27. d2.push([i, parseInt(Math.random() * 8)]);
  28. }
  29. //default flot options
  30. var options = {
  31. series: { curvedLines: { active: true } },
  32. grid: { hoverable: true } // <- generally activate hover
  33. };
  34. //plotting with per series adjustments
  35. $.plot($("#flotContainer"), [
  36. { //series 1
  37. data: d1,
  38. lines: { show: true, lineWidth: 3 },
  39. hoverable: false, // <- overwrite hoverable with false
  40. curvedLines: {
  41. apply: true // <- set apply <- curve only this data series
  42. }
  43. }, { //series 2
  44. data: d1,
  45. points: { show: true }
  46. }, { //series 3
  47. data: d2,
  48. points: { show: true, radius: 5 }
  49. }], options);
  50. //adding hover text
  51. $("#flotContainer").bind("plothover", function (event, pos, item) {
  52. if (item) {
  53. $("#hoverText").text("point at: " + pos.x.toFixed(2) + " / " + pos.y.toFixed(2))
  54. } else {
  55. $("#hoverText").text("point at: - / -")
  56. }
  57. });
  58. });
  59. </script>
  60. </head>
  61. <h4>CurvedLines: customizing and mixing</h4>
  62. <div class="text-block"> <span id="hoverText">point at: - / -</span>
  63. </div>
  64. <div id="flotContainer" class="chart-style"></div>
  65. <div class="text-block">The example shows two datasets (d1, d2) plotted using different styles (curved line, points, bigger points). The points are hoverable, the curved line is not.</div>
  66. <div class="text-block">To achieve such mixed plots you have to define some settings on a per series level. In the example the curved line plugin is generally set to active (as default in the options object) but will be applied only to the first series. Similarly hovering is deactivated for the first series. The combination of "replotting" (series 1 and 2 both origin form dataset d1) and per series settings allows you to mix different plotting styles and settings in one canvas.</div>
  67. <a href="index.html">Return to CurvedLines Examples list</a>
  68. </body>
  69. </html>