Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate X labels on horizontal scroll #5489

Open
pareshpchibaree opened this issue Oct 18, 2024 · 2 comments
Open

Duplicate X labels on horizontal scroll #5489

pareshpchibaree opened this issue Oct 18, 2024 · 2 comments

Comments

@pareshpchibaree
Copy link

I'm using line chart and binding float values from -1 to 1 at y axis and dates in x axis labels. What I could see that dates are getting duplicates one behind another initially after setting the data set and while scrolling as well. The issue is coming when I have more than 15-20 dates when scrolling is available otherwise I couldn't see the duplicate x labels.

I have debugged my code as well I could see no duplicate dates/entries in x labels array, FYI.

Sometimes, some weird output.
1

Sometimes duplicate values.
2

Please help any one what I'm doing wrong here.

Sharing my 2 functions where I'm configuring chart and setting up the data.

private fun configureLineChart() {

    // Configuring x axis
    binding.chartTimeSeries.xAxis.apply {
        position = XAxis.XAxisPosition.BOTTOM
        labelRotationAngle = 280f
        setDrawGridLines(false)
        setDrawAxisLine(true)
        setDrawLabels(true)
        yOffset = 10f
    }

    // Configuring y axis
    binding.chartTimeSeries.axisLeft.apply {
        setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART)
        mAxisMinimum = -1f
        setLabelCount(5, true)
        setDrawAxisLine(true)
        setDrawZeroLine(false)
        setDrawGridLines(false)
        axisMinimum = -1f
        axisMaximum = 1f
        valueFormatter = YAxisDecimalLabelFormatter()
    }

    // Configuring settings of chart
    binding.chartTimeSeries.apply {

        // Disabling right axis, description, legends
        axisRight.isEnabled = false
        description.isEnabled = false
        legend.isEnabled = false

        // Enabling touch gestures, scaling and dragging and disabling pinch to zoom
        setTouchEnabled(true)
        setScaleEnabled(false)
        setPinchZoom(false)
        isDoubleTapToZoomEnabled = false

        //Disabling grid
        setDrawGridBackground(false)

    }

}

// Calling this function after above one
private fun loadTimeSeriesChartData(data: ArrayList) {

    binding.chartTimeSeries.clear()

    // Creating data set
    data.reverse()
    val xAxisDateLabel = arrayListOf<String>()
    val xAxisActivityEntries = arrayListOf<Entry>()
    data.forEachIndexed { index, activity ->
        xAxisDateLabel.add(activity.activityDate)
        if (!activity.value.isNullOrEmpty()) {
            xAxisActivityEntries.add(
                Entry(index.toFloat(), activity.value.toFloat().roundOffDecimal())
            )
        } else {
            xAxisActivityEntries.add(Entry(index.toFloat(), 0f))
        }
    }

    // Adding value formatter for x axis labels
    binding.chartTimeSeries.xAxis.apply {
        valueFormatter = IndexAxisValueFormatter(xAxisDateLabel)
        setLabelCount(data.size, false)
    }

    // Setting chart data to plot after clearing values
    setTimeSeriesChartData(xAxisActivityEntries)

    // Configuring settings of chart after data is set
    binding.chartTimeSeries.apply {

        extraTopOffset = 20f
        extraBottomOffset = 20f

        // Setting minimum x labels to display
        setVisibleXRangeMaximum(10f)

        moveViewToX(xAxisActivityEntries.last().x)

        // Redrawing chart to update data values
        invalidate()

    }

}
@pareshprajapati1990
Copy link

Any updates on this? Does anyone have any idea how to solve this issue?

@pareshprajapati1990
Copy link

@PhilJay and team, Please help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants