ErrorBarSeries.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* *
  2. * (c) 2010-2019 Torstein Honsi
  3. *
  4. * License: www.highcharts.com/license
  5. */
  6. 'use strict';
  7. import H from '../parts/Globals.js';
  8. import '../parts/Utilities.js';
  9. import '../parts/Options.js';
  10. import './BoxPlotSeries.js';
  11. var noop = H.noop,
  12. seriesType = H.seriesType,
  13. seriesTypes = H.seriesTypes;
  14. /**
  15. * Error bars are a graphical representation of the variability of data and are
  16. * used on graphs to indicate the error, or uncertainty in a reported
  17. * measurement.
  18. *
  19. * @sample highcharts/demo/error-bar/
  20. * Error bars on a column series
  21. * @sample highcharts/series-errorbar/on-scatter/
  22. * Error bars on a scatter series
  23. *
  24. * @extends plotOptions.boxplot
  25. * @product highcharts highstock
  26. * @optionparent plotOptions.errorbar
  27. */
  28. seriesType('errorbar', 'boxplot', {
  29. /**
  30. * The main color of the bars. This can be overridden by
  31. * [stemColor](#plotOptions.errorbar.stemColor) and
  32. * [whiskerColor](#plotOptions.errorbar.whiskerColor) individually.
  33. *
  34. * @sample {highcharts} highcharts/plotoptions/error-bar-styling/
  35. * Error bar styling
  36. *
  37. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  38. * @default #000000
  39. * @since 3.0
  40. * @product highcharts
  41. */
  42. color: '#000000',
  43. grouping: false,
  44. /**
  45. * The parent series of the error bar. The default value links it to
  46. * the previous series. Otherwise, use the id of the parent series.
  47. *
  48. * @since 3.0
  49. * @product highcharts
  50. */
  51. linkedTo: ':previous',
  52. tooltip: {
  53. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.low}</b> - <b>{point.high}</b><br/>'
  54. },
  55. /**
  56. * The line width of the whiskers, the horizontal lines marking low
  57. * and high values. When `null`, the general
  58. * [lineWidth](#plotOptions.errorbar.lineWidth) applies.
  59. *
  60. * @sample {highcharts} highcharts/plotoptions/error-bar-styling/
  61. * Error bar styling
  62. *
  63. * @type {number}
  64. * @since 3.0
  65. * @product highcharts
  66. */
  67. whiskerWidth: null
  68. // Prototype members
  69. }, {
  70. type: 'errorbar',
  71. pointArrayMap: ['low', 'high'], // array point configs are mapped to this
  72. toYData: function (point) { // return a plain array for speedy calculation
  73. return [point.low, point.high];
  74. },
  75. pointValKey: 'high', // defines the top of the tracker
  76. doQuartiles: false,
  77. drawDataLabels: seriesTypes.arearange ?
  78. function () {
  79. var valKey = this.pointValKey;
  80. seriesTypes.arearange.prototype.drawDataLabels.call(this);
  81. // Arearange drawDataLabels does not reset point.y to high,
  82. // but to low after drawing (#4133)
  83. this.data.forEach(function (point) {
  84. point.y = point[valKey];
  85. });
  86. } :
  87. noop,
  88. // Get the width and X offset, either on top of the linked series column or
  89. // standalone
  90. getColumnMetrics: function () {
  91. return (this.linkedParent && this.linkedParent.columnMetrics) ||
  92. seriesTypes.column.prototype.getColumnMetrics.call(this);
  93. }
  94. });
  95. /**
  96. * A `errorbar` series. If the [type](#series.errorbar.type) option
  97. * is not specified, it is inherited from [chart.type](#chart.type).
  98. *
  99. * @extends series,plotOptions.errorbar
  100. * @excluding dataParser, dataURL, stack, stacking
  101. * @product highcharts
  102. * @apioption series.errorbar
  103. */
  104. /**
  105. * An array of data points for the series. For the `errorbar` series
  106. * type, points can be given in the following ways:
  107. *
  108. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  109. * to `x,low,high`. If the first value is a string, it is applied as the name
  110. * of the point, and the `x` value is inferred. The `x` value can also be
  111. * omitted, in which case the inner arrays should be of length 2\. Then the
  112. * `x` value is automatically calculated, either starting at 0 and
  113. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  114. * series options.
  115. * ```js
  116. * data: [
  117. * [0, 10, 2],
  118. * [1, 1, 8],
  119. * [2, 4, 5]
  120. * ]
  121. * ```
  122. *
  123. * 2. An array of objects with named values. The following snippet shows only a
  124. * few settings, see the complete options set below. If the total number of
  125. * data points exceeds the series'
  126. * [turboThreshold](#series.errorbar.turboThreshold), this option is not
  127. * available.
  128. * ```js
  129. * data: [{
  130. * x: 1,
  131. * low: 0,
  132. * high: 0,
  133. * name: "Point2",
  134. * color: "#00FF00"
  135. * }, {
  136. * x: 1,
  137. * low: 5,
  138. * high: 5,
  139. * name: "Point1",
  140. * color: "#FF00FF"
  141. * }]
  142. * ```
  143. *
  144. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  145. * Arrays of numeric x and y
  146. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  147. * Arrays of datetime x and y
  148. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  149. * Arrays of point.name and y
  150. * @sample {highcharts} highcharts/series/data-array-of-objects/
  151. * Config objects
  152. *
  153. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  154. * @extends series.arearange.data
  155. * @excluding dataLabels, drilldown, marker, states
  156. * @product highcharts
  157. * @apioption series.errorbar.data
  158. */