@@ -68,12 +68,11 @@ const ErrorBarsPlugin = {
6868 * compute error bars width in pixel or percent
6969 * @param chart chartjs instance
7070 * @param horizontal orientation
71- * @param options plugin options
71+ * @param width plugin option width
7272 * @returns {* } width in pixel as number
7373 * @private
7474 */
75- _computeWidth ( chart , horizontal , options ) {
76- const width = options . width ;
75+ _computeWidth ( chart , horizontal , width ) {
7776 let widthInPx = width ;
7877
7978 try {
@@ -102,7 +101,7 @@ const ErrorBarsPlugin = {
102101 console . error ( e ) ;
103102 } finally {
104103 if ( Number . isNaN ( widthInPx ) ) {
105- widthInPx = options . width ;
104+ widthInPx = width ;
106105 }
107106 }
108107 return widthInPx ;
@@ -170,7 +169,9 @@ const ErrorBarsPlugin = {
170169 const horizontal = this . _isHorizontal ( chart ) ;
171170 const vScale = horizontal ? chart . scales [ 'x-axis-0' ] : chart . scales [ 'y-axis-0' ] ;
172171
173- const errorBarWidth = this . _computeWidth ( chart , horizontal , options ) ;
172+ const errorBarWidths = ( Array . isArray ( options . width ) ? options . width : [ options . width ] ) . map ( ( w ) => this . _computeWidth ( chart , horizontal , w ) ) ;
173+ const errorBarColors = Array . isArray ( options . color ) ? options . color : [ options . color ] ;
174+
174175
175176 const ctx = chart . ctx ;
176177 ctx . save ( ) ;
@@ -182,7 +183,7 @@ const ErrorBarsPlugin = {
182183 if ( ! cur ) {
183184 return ;
184185 }
185- let hasLabelProperty = cur . hasOwnProperty ( bar . label ) ;
186+ const hasLabelProperty = cur . hasOwnProperty ( bar . label ) ;
186187 let errorBarData = null ;
187188
188189 // common scale such as categorical
@@ -193,19 +194,26 @@ const ErrorBarsPlugin = {
193194 errorBarData = cur [ bar . label . label ] ;
194195 }
195196
196- // error bar data for the barchart bar or point in linechart
197- if ( errorBarData ) {
198- const errorBarColor = options . color ? options . color : bar . color ;
199- const value = vScale . getRightValue ( bar . value ) ;
197+ if ( ! errorBarData ) {
198+ return ;
199+ }
200200
201- const plusValue = options . absoluteValues ? Math . abs ( errorBarData . plus ) : ( value + Math . abs ( errorBarData . plus ) ) ;
202- const minusValue = options . absoluteValues ? Math . abs ( errorBarData . minus ) : ( value - Math . abs ( errorBarData . minus ) ) ;
201+ const errorBars = Array . isArray ( errorBarData ) ? errorBarData : [ errorBarData ] ;
202+ const value = vScale . getRightValue ( bar . value ) ;
203+
204+ errorBars . forEach ( ( errorBar , ei ) => {
205+ // error bar data for the barchart bar or point in linechart
206+ const errorBarColor = errorBarColors [ ei % errorBarColors . length ] ? errorBarColors [ ei % errorBarColors . length ] : bar . color ;
207+ const errorBarWidth = errorBarWidths [ ei % errorBarWidths . length ] ;
208+
209+ const plusValue = options . absoluteValues ? errorBar . plus : ( value + errorBar . plus ) ;
210+ const minusValue = options . absoluteValues ? errorBar . minus : ( value + errorBar . minus ) ;
203211
204212 const plus = vScale . getPixelForValue ( plusValue ) ;
205213 const minus = vScale . getPixelForValue ( minusValue ) ;
206214
207215 this . _drawErrorBar ( ctx , bar , plus , minus , errorBarColor , errorBarWidth , horizontal ) ;
208- }
216+ } ) ;
209217 } ) ;
210218 } ) ;
211219
0 commit comments