PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/getting-started/dataviz/chart/error-bars.md

https://github.com/ejazkhan/kendo-docs
Markdown | 229 lines | 187 code | 42 blank | 0 comment | 0 complexity | 61a40ac8b27e73fbe2a49f37f24ce583 MD5 | raw file
  1. ---
  2. title: Error Bars
  3. meta_title: Configuration guide for the chart ErrorBars
  4. meta_description: How to configure the error bars of a chart, bind them to the series data and set the value.
  5. slug: chart-error-bars
  6. publish: true
  7. ---
  8. #Error bars
  9. Error bars can be used to show variability of data. This help topic describes how to use them in a Kendo UI Chart.
  10. ##Configuring the chart error bars
  11. The Error bars are specified as part of the series definition and are supported for the following series types:
  12. * Area
  13. * Vertical Area
  14. * Column
  15. * Bar
  16. * Line
  17. * Vertical Line
  18. * Scatter
  19. * ScatterLine
  20. The low and high value for the error bars can either be bound to the data or be calculated from the point or series values.
  21. ##Data binding
  22. ###Binding to categorical series
  23. To bind the error bars low and high value when using categorical series, you should set the [errorLowField](/kendo-ui/api/dataviz/chart#configuration-series.errorLowField) and [errorHighField](/kendo-ui/api/dataviz/chart#configuration-series.errorHighField) options to the fields in the data that hold the low and high value.
  24. #### Example
  25. <div id="chart"></div>
  26. <script>
  27. $("#chart").kendoChart({
  28. series: [{
  29. type: "column",
  30. errorLowField: "low",
  31. errorHighField: "high",
  32. data: [{value: 4.743, low: 4.5, high: 5}, {value: 7.295, low: 7, high: 8},
  33. {value: 6.376, low: 5, high: 6.5}]
  34. }]
  35. });
  36. </script>
  37. ###Binding to scatter series
  38. Error bars can be displayed for the series x value, y value or both. To set the low and high fields for the series x value, you should set the [xErrorLowField](/kendo-ui/api/dataviz/chart#configuration-series.xErrorLowField) and [xErrorHighField](/kendo-ui/api/dataviz/chart#configuration-series.xErrorHighField) series options. The low and high fields for the series y value, can be specified with the [yErrorLowField](/kendo-ui/api/dataviz/chart#configuration-series.yErrorLowField) and [yErrorHighField](/kendo-ui/api/dataviz/chart#configuration-series.yErrorHighField) options.
  39. #### Example: binding the error bars for the series x value
  40. <div id="chart"></div>
  41. <script>
  42. $("#chart").kendoChart({
  43. series: [{
  44. type: "scatter",
  45. xErrorLowField: "low",
  46. xErrorHighField: "high",
  47. data: [{x: 6.4, y: 13.4, low: 5, high: 7}, {x: 1.7, y: 11, low: 1, high: 3},
  48. {x: 5.4, y: 8, low: 3, high: 6}]
  49. }]
  50. });
  51. </script>
  52. #### Example: binding the error bars for the series y value
  53. <div id="chart"></div>
  54. <script>
  55. $("#chart").kendoChart({
  56. series: [{
  57. type: "scatter",
  58. yErrorLowField: "low",
  59. yErrorHighField: "high",
  60. data: [{x: 6.4, y: 13.4, low: 12, high: 14}, {x: 1.7, y: 11, low: 11, high: 14},
  61. {x: 5.4, y: 8, low: 5, high: 8}]
  62. }]
  63. });
  64. </script>
  65. ##Setting the error bars value
  66. The error bars low and high value can be calculated based on the series point values. To set the error bars value for categorical series, you should specify the [series.errorBars.value](/kendo-ui/api/dataviz/chart#configuration-series.errorBars.value) option. For scatter series, you should set the [series.errorBars.xValue](/kendo-ui/api/dataviz/chart#configuration-series.errorBars.xValue) or [series.errorBars.yValue](/kendo-ui/api/dataviz/chart#configuration-series.errorBars.yValue) options or both.
  67. ###Setting a numeric value
  68. If the error bars value is set to a number(must not be negative), then the low and high value will be calculated by subtracting/adding the value to the series value.
  69. ####Example: setting a numeric value for categorical series
  70. <div id="chart"></div>
  71. <script>
  72. $("#chart").kendoChart({
  73. series: [{
  74. type: "column",
  75. errorBars: {
  76. value: 1
  77. },
  78. data: [{value: 4.743}, {value: 7.295}, {value: 6.376}]
  79. }]
  80. });
  81. </script>
  82. ####Example: setting a numeric value for scatter series
  83. <div id="chart"></div>
  84. <script>
  85. $("#chart").kendoChart({
  86. series: [{
  87. type: "scatter",
  88. errorBars: {
  89. yValue: 2
  90. },
  91. data: [{x: 6.4, y: 13.4}, {x: 1.7, y: 11}, {x: 5.4, y: 8}]
  92. }]
  93. });
  94. </script>
  95. ###Setting an array value
  96. The difference can also be set separately for the low and high value by setting an array with two numeric values. In this case, the low value will be calculated by subtracting the array first value from the point value and the high value will be calculated by adding the second value to the point value.
  97. ####Example: setting an array value for categorical series
  98. <div id="chart"></div>
  99. <script>
  100. $("#chart").kendoChart({
  101. series: [{
  102. type: "column",
  103. errorBars: {
  104. value: [0.7, 1]
  105. },
  106. data: [{value: 4.743}, {value: 7.295}, {value: 6.376}]
  107. }]
  108. });
  109. </script>
  110. ####Example: setting an array value for scatter series
  111. <div id="chart"></div>
  112. <script>
  113. $("#chart").kendoChart({
  114. series: [{
  115. type: "scatter",
  116. errorBars: {
  117. yValue: [1, 2]
  118. },
  119. data: [{x: 6.4, y: 13.4}, {x: 1.7, y: 11}, {x: 5.4, y: 8}]
  120. }]
  121. });
  122. </script>
  123. ###Setting a percentage value
  124. It is also possible to set the difference as percentage of the point value. To achieve this, you should set a string value in the format "percenatage(n)" where `n` indicates the percent value.
  125. ####Example: setting a percentage value
  126. <div id="chart"></div>
  127. <script>
  128. $("#chart").kendoChart({
  129. series: [{
  130. errorBars: {
  131. value: "percentage(20)"
  132. },
  133. data: [{value: 4.743}, {value: 7.295}, {value: 6.376}]
  134. }]
  135. });
  136. </script>
  137. ###Setting a statistical value
  138. The error bars support statistical calculations based on the series data. The supported types are [standard error](http://en.wikipedia.org/wiki/Standard_error) and [population standard deviation](http://en.wikipedia.org/wiki/Standard_deviation). To specify that standard error should be used, you should set `"stderr"` as value. To use standard deviation, you should set `"stddev"` with an optional number between parentheses appended at the end. The number will be multiplied by the calculated standard deviation value.
  139. ####Example: using standard error
  140. <div id="chart"></div>
  141. <script>
  142. $("#chart").kendoChart({
  143. series: [{
  144. errorBars: {
  145. value: "stderr"
  146. },
  147. data: [{value: 4.743}, {value: 7.295}, {value: 6.376}]
  148. }]
  149. });
  150. </script>
  151. ####Example: using standard deviation
  152. <div id="chart"></div>
  153. <script>
  154. $("#chart").kendoChart({
  155. series: [{
  156. errorBars: {
  157. value: "stddev(0.5)"
  158. },
  159. data: [{value: 4.743}, {value: 7.295}, {value: 6.376}]
  160. }]
  161. });
  162. </script>
  163. ###Calculating the low and high value with a custom function.
  164. If a custom algorithm is needed to calculate the low and high value, then you can specify a function. The function accepts an object with the following fields as parameter:
  165. * dataItem the point data item
  166. * value - the point value
  167. * index the point index in the series data
  168. * category the point category value if a categorical chart is used
  169. * series the series configuration
  170. and should return a valid error bar value.
  171. ####Example: using different percentages for the low and high value
  172. <div id="chart"></div>
  173. <script>
  174. $("#chart").kendoChart({
  175. series: [{
  176. errorBars: {
  177. value: function(data) {
  178. var value = data.value,
  179. lowPercentage = value * 0.05,
  180. highPercentage = value * 0.1;
  181. return [lowPercentage, highPercentage];
  182. }
  183. },
  184. data: [{value: 4.743}, {value: 7.295}, {value: 6.376}]
  185. }]
  186. });
  187. </script>