Series (JChart2D)
- Purpose: A Series in JChart2D represents an ordered collection of data points plotted on a chart (usually along a time or numerical axis).
- Common types:
- SimpleSeries / ITrace2D implementations (e.g., Trace2DLtd, Trace2DSimple) for line/point charts.
- ValueSeries for non-time numerical sequences.
- Core responsibilities:
- Store data points (x/y or time/value pairs).
- Expose methods to add, remove, or update points.
- Provide metadata such as name, color, stroke, and visibility.
- Performance behavior:
- Some implementations (like Trace2DLtd) limit stored points to a fixed buffer size for constant memory and steady rendering performance.
- Others keep all points; use limited traces for high-frequency data.
- Rendering interaction:
- A Series is rendered by a Trace/Renderer (e.g., TracePainter) which reads the Series data and draws lines, markers, fills, etc.
- Series often notify the chart or trace listeners on change so the display can repaint.
- Threading:
- Updates from background threads should be synchronized or posted to the Swing EDT to avoid concurrency issues.
- Typical API methods (examples):
- addPoint(x, y) / addPoint(TimeStamp, value)
- removePoint(index) / clear()
- setName(String) / setColor(Color) / setStroke(Stroke)
- setVisible(boolean) / isVisible()
- Usage tips:
- Use limited traces for streaming data to avoid memory bloat.
- Batch updates and call repaint once after multiple changes.
- Configure renderers for desired markers, line smoothing, and anti-aliasing.
- When to extend:
- Extend Series implementations when you need custom storage, interpolation, or specialized downsampling.
If you want, I can show a short code example for creating and updating a Trace2DLtd series.
Leave a Reply