Hi.
I have a line chart where i add data continuously from different sensors.
The code looks like this
protected open fun setupChart() {
surface = requireView().findViewById(R.id.sciChartId)
xAxis = NumericAxis(context).apply {
autoRange = AutoRange.Always
drawMajorGridLines = false
drawMajorBands = false
drawMinorGridLines = false
}
yAxis = NumericAxis(context).apply {
drawMajorGridLines = false
drawMajorBands = false
drawMinorGridLines = false
axisAlignment = AxisAlignment.Left
// axisId ="First id"
}
dataSeries1 = XyDataSeries(Double::class.javaObjectType, Double::class.javaObjectType).apply {
seriesName = "Line A"
acceptsUnsortedData = true
}
val line1Color = Color.BLACK // ColorUtil.argb(0xFF, 0xFF, 0xFF, 0x00)
val line1 = FastLineRenderableSeries().apply {
strokeStyle = SolidPenStyle(line1Color, true, 1F, null)
dataSeries = dataSeries1
// yAxisId = "SecondId"
}
val legendModifier = LegendModifier(context).apply {
setLegendPosition(Gravity.TOP or Gravity.START, 16)
setOrientation(Orientation.VERTICAL)
setSourceMode(SourceMode.AllSeries)
}
series.add(line1)
UpdateSuspender.using(surface) {
surface.xAxes.add(xAxis)
surface.yAxes.add(yAxis)
// surface.yAxes.add(yAxisTwo)
surface.renderableSeries.addAll(series)
surface.chartModifiers.add(legendModifier)
surface.setBackgroundColor(Color.WHITE)
series.forEach {
AnimationsHelper.createAnimator(
it,
SweepXyTransformation(XyRenderPassData::class.java),
3000,
350,
DecelerateInterpolator(),
FloatEvaluator(),
0f,
1f
).start()
}
}
addXAxisDragModifier()
addZoomPanModifier()
addZoomExtentModifier()
addPinchZoom()
surface.zoomExtents()
}
And the code adding data looks like this
dataSeries1.append(value, someOtherValue)
I understand that zooming is not possible when you set AutoRange to Always.
However i have not seen any working example where zooming is enabled at the same time as you add data continually.
Is it possible to zoom at all with real time without setting autoRange and if yes can you refer to any working example you have
- Arbon Vata asked 2 years ago
- You must login to post comments
Hi Arbon,
For this case you need to manage VisibleRange for X/YAxis manually and set it after you append new data. We have an example in our demo app which implements this approach. To simulate AutoRange.Always behavior when it’s needed you can set VisibleRange to DataRange value ( or if you’re using GrowBy and need to concider it then need to use MaximumRange ):
xAxis.visibleRange.set(xAxis.dataRange)
xAxis.visibleRange.set(xAxis.maximumRange)
Best regards,
Yura
- Yura Khariton answered 2 years ago
- You must login to post comments
Please login first to submit.