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.

69 lines
2.2 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. ### html ###
  2. <h4>CurvedLines: customizing and mixing</h4>
  3. <div class="text-block"> <span id="hoverText">point at: - / -</span>
  4. </div>
  5. <div id="flotContainer" class="chart-style"></div>
  6. <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>
  7. <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>
  8. ### css ###
  9. .chart-style {
  10. width: 600px;
  11. height: 340px;
  12. margin-bottom: 15px;
  13. }
  14. .text-block {
  15. margin-bottom: 15px;
  16. }
  17. ### javascript ###
  18. //some random data
  19. var d1 = []; var last = 0;
  20. for (var i = 0; i <= 40; i += (2 + parseInt(Math.random() * 5))) {
  21. last = last + ((Math.random() * 3) - 1.5)
  22. d1.push([i, parseInt(last)]);
  23. }
  24. var d2 = [];
  25. for (var i = 2; i <= $(d1).get(-1)[0]; i += (2 + parseInt(Math.random() * 5))) {
  26. d2.push([i, parseInt(Math.random() * 8)]);
  27. }
  28. //default flot options
  29. var options = {
  30. series: { curvedLines: { active: true } },
  31. grid: { hoverable: true } // <- generally activate hover
  32. };
  33. //plotting with per series adjustments
  34. $.plot($("#flotContainer"), [
  35. { //series 1
  36. data: d1,
  37. lines: { show: true, lineWidth: 3 },
  38. hoverable: false, // <- overwrite hoverable with false
  39. curvedLines: {
  40. apply: true // <- set apply <- curve only this data series
  41. }
  42. }, { //series 2
  43. data: d1,
  44. points: { show: true }
  45. }, { //series 3
  46. data: d2,
  47. points: { show: true, radius: 5 }
  48. }], options);
  49. //adding hover text
  50. $("#flotContainer").bind("plothover", function (event, pos, item) {
  51. if (item) {
  52. $("#hoverText").text("point at: " + pos.x.toFixed(2) + " / " + pos.y.toFixed(2))
  53. } else {
  54. $("#hoverText").text("point at: - / -")
  55. }
  56. });