Pre loader

AutoRange and zoomExtents() crop the top points

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

When setting yAxis to have auto range enabled or when manually calling chartSurface.zoomExtents() after adding new data to chart, the top point are cropped (not shown in the chart). I have attached an image that shows this phenomenon (note: bottom part of the chart is cropped out of the image).

Below is full code of an Activity that reproduces the problem. I also updated the attached image that shows the result of the following code. As you can see both red points with y value of 1.1f are cropped out of the chart.

class MainActivity : AppCompatActivity()
{
    private val chartBuilder by lazy { SciChartBuilder.instance() }
    private val chartSurface by lazy { createChartSurface() }

    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)

        SciChartBuilder.init(this)
        setContentView(R.layout.activity_main)

        val background = findViewById<ViewGroup>(R.id.background)
        background.addView(chartSurface)

        addPoints()
    }

    private fun createChartSurface(): SciChartSurface
    {
        val surface = SciChartSurface(this)

        val xAxis = chartBuilder.newNumericAxis()
            .withAxisTitle("X Axis title")
            .withVisibleRange(0.0, 1.0)
            .withAutoRangeMode(AutoRange.Always)
            .build()

        val yAxis = chartBuilder.newNumericAxis()
            .withAxisTitle("Y Axis title")
            .withVisibleRange(0.0, 1.0)
            .withAutoRangeMode(AutoRange.Always)
            .build()

        Collections.addAll(surface.xAxes, xAxis)
        Collections.addAll(surface.yAxes, yAxis)

        surface.renderableSeries.add(createSeries(Color.RED))
        surface.renderableSeries.add(createSeries(Color.BLUE))

        return surface
    }

    private fun createSeries(color: Int): FastLineRenderableSeries
    {
        val lineData = chartBuilder.newXyDataSeries(Long::class.javaObjectType, Float::class.javaObjectType)
            .withSeriesName("series")
            .build()

        return chartBuilder.newLineSeries()
            .withDataSeries(lineData)
            .withIsVisible(true)
            .withStrokeStyle(color, 2f, true)
            .build()
    }

    private fun addPoints()
    {
        val xValues = LongValues(longArrayOf(0, 1, 2, 3, 4, 5))

        @Suppress("UNCHECKED_CAST")
        var lineData = chartSurface.renderableSeries[0].dataSeries as XyDataSeries<Long, Float>
        lineData.append(xValues, FloatValues(floatArrayOf(0.9f, 1f, 1.1f, 0.9f, 1.1f, 1f)))

        @Suppress("UNCHECKED_CAST")
        lineData = chartSurface.renderableSeries[1].dataSeries as XyDataSeries<Long, Float>
        lineData.append(xValues, FloatValues(floatArrayOf(0f, 0f, 0f, 0f, 0f, 0f)))
    }
}
Version
2.0.0.1884
  • You must to post comments
0
0

Hi Miha,

Have you tried to add some GrowBy for your yAxis – this should provide some additional spacing for yAxis:

val yAxis = chartBuilder.newNumericAxis()
        .withAxisTitle("Y Axis title")
        .withVisibleRange(0.0, 1.0)
        .withGrowBy(0.1, 0.1)
        .withAutoRangeMode(AutoRange.Always)
        .build()

I’m not sure that there is something other we can do in this case – point lies directly on the edge of viewport and it would be hard to prevent it’s clipping in this case (especially in case if line thickness is >1px)

Hope this will help you!

Best regards,
Yura

  • MIha Rozina
    Point is clipped even if thickness is 1px. I expect auto range to include all points into the viewport. Even if thickness is >1px I don’t see why auto range would not be able to include all points into viewport. Otherwise, what is the point of auto range?
  • MIha Rozina
    A side question. I would like to find out what withGrowBy() / setGrowBy() functions do (see their manual). How do I go about finding the info? I found this link, but it has no useful information on what the function actually does.
  • Yura Khariton
    Unfortunately we don’t have a seperate tutorial for GrowBy property. It just adds additinal during calculation of MaximumRange for axis which is used for auto range. So when you set GrowBy(0.1, 0.2) – this increases the axis extents by 10% (min) and 20% (max) outside of the DataRange which is calculated only based on points from data set
  • Yura Khariton
    Regarding your previous question about autorange calculations – we don’t consider how RenderableSeries draws itself and operate only with values provided by DataSeries – so if data set contains data points in range from 0 to 100 then during autorange VisibleRange should be assinged to (0, 100). You can check that VisibleRange of axis should include all data points from your data series. The problem occurs during drawing and there is not much we can do in this case ( there is some loss of precision during convertion to pixels and we can’t draw line which has 0.5 pixel thickness). That’s why we’ve added GrowBy property which allows to workaround this limitations.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies