YCharts icon indicating copy to clipboard operation
YCharts copied to clipboard

Wrong plot of data in Line Chart

Open Randomboiii03 opened this issue 1 year ago • 4 comments

Did I do wrong when setting the chart? All I did is put my data in the chart component, as you can see the data in y value is 1 and the highest is 2 which my data has no 0 value, its 1 and 2s only. Why does it do this, is it my setup fault or is it a bug? Anyone can help me? Thanks

@Composable
private fun getLineChartData(pointData: List<Point>, yScale: Int): LineChartData {
    return LineChartData(
        linePlotData = LinePlotData(
            lines = listOf(
                Line(
                    dataPoints = pointData,
                    LineStyle(
                        color = MaterialTheme.colorScheme.onTertiaryContainer,
                        width = 6f,
                        lineType = LineType.SmoothCurve(isDotted = false)
                    ),
                    IntersectionPoint(
                        color = MaterialTheme.colorScheme.onTertiaryContainer,
                        radius = 4.dp
                    ),
                    SelectionHighlightPoint(color = MaterialTheme.colorScheme.onTertiaryContainer),
                    ShadowUnderLine(
                        alpha = 0.5f,
                        brush = Brush.verticalGradient(
                            colors = listOf(
                                MaterialTheme.colorScheme.onTertiaryContainer,
                                Color.Transparent
                            )
                        )
                    ),
                    SelectionHighlightPopUp()
                )
            )
        ),
        backgroundColor = MaterialTheme.colorScheme.tertiaryContainer,
        xAxisData = getXAxisData(pointData = pointData),
        yAxisData = getYAxisData(yScale = yScale),
        gridLines = GridLines(
            color = MaterialTheme.colorScheme.onTertiaryContainer,
            enableVerticalLines = false
        ),
        paddingRight = 0.dp
    )
}

419999724_401804508903006_5330249170642921648_n

Randomboiii03 avatar Jan 21 '24 12:01 Randomboiii03

Same issue here. When you start the y-axis with 0 but there's no 0 correlated value in your data points, the axis ie either pushed further down to compensate for that "missing" point in your data points and assigns the lowest value to the 0 value on the y-axis.

This needs fixing. I haven't found a way to circumvent it.

YSNBx avatar Jan 21 '24 16:01 YSNBx

Same issue here. When you start the y-axis with 0 but there's no 0 correlated value in your data points, the axis ie either pushed further down to compensate for that "missing" point in your data points and assigns the lowest value to the 0 value on the y-axis.

This needs fixing. I haven't found a way to circumvent it.

Did you find any work around for this problem?

Randomboiii03 avatar Jan 22 '24 03:01 Randomboiii03

I haven't, unfortunately. Let me know if you find any workaround.

YSNBx avatar Jan 27 '24 20:01 YSNBx

On looking at the source code.. found out the cause of this issue.. They are setting the min and max values for x and y axis based on the data that we set to plot the charts.

For example, in your case, the data set consists of only 1 and 2.. so here the min and max value for your y axis will be taken as 1 and 2 respectively. Instead the min and max value for the y axis should be from the label that you set to the axis which is 0 and 2.

Either the the sdk has to give the user to set the min and max values explicitly or the min and max values should be calculated from the axis data that the user provides instead of the points data that is used to plot the points in the chart.

saiteja962 avatar Apr 28 '24 15:04 saiteja962