Series sets the values that should be displayed as the line chart with the provided label. The values that should not be displayed on the line chart should be represented as math.NaN values on the values slice. Subsequent calls with the same label replace any previously provided values.
(label string, values []float64, opts ...SeriesOption)
| 247 | // as math.NaN values on the values slice. |
| 248 | // Subsequent calls with the same label replace any previously provided values. |
| 249 | func (lc *LineChart) Series(label string, values []float64, opts ...SeriesOption) error { |
| 250 | if label == "" { |
| 251 | return errors.New("the label cannot be empty") |
| 252 | } |
| 253 | |
| 254 | lc.mu.Lock() |
| 255 | defer lc.mu.Unlock() |
| 256 | |
| 257 | series := newSeriesValues(values) |
| 258 | for _, opt := range opts { |
| 259 | opt.set(series) |
| 260 | } |
| 261 | if series.xLabelsSet { |
| 262 | for i, t := range series.xLabels { |
| 263 | if i < 0 { |
| 264 | return fmt.Errorf("invalid key %d -> %q provided in SeriesXLabels, keys must be positive", i, t) |
| 265 | } |
| 266 | if t == "" { |
| 267 | return fmt.Errorf("invalid label %d -> %q provided in SeriesXLabels, values cannot be empty", i, t) |
| 268 | } |
| 269 | } |
| 270 | lc.xLabels = series.xLabels |
| 271 | } |
| 272 | |
| 273 | lc.series[label] = series |
| 274 | yMin, yMax := lc.yMinMax() |
| 275 | lc.yMin = yMin |
| 276 | lc.yMax = yMax |
| 277 | return nil |
| 278 | } |
| 279 | |
| 280 | // SetThresholdLine updates the horizontal guide rendered across the plotted |
| 281 | // area at the provided Y value. |