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

The chart is nor displayed. WebView not displayed because it is too large to fit into a software layer (or drawing cache) #294

Open
Child0fTheSun opened this issue Oct 25, 2024 · 2 comments

Comments

@Child0fTheSun
Copy link

Hi. Sorry for my bad English. I have a screen that displays a pie chart and a combo chart of lines and bars. In portrait orientation there is no problem, the charts are displayed. However, in landscape orientation the combo chart is not displayed, and in the logs the message "WebView not displayed because it is too large to fit into a software layer (or drawing cache), needs 11107800 bytes, only 10368000 available" is constantly displayed. Could someone please tell me how to fix this problem?

laout.xml code:
`<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.general.GeneralFragment">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:overScrollMode="ifContentScrolls"
    android:paddingVertical="@dimen/margin_small">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="832dp"
        android:orientation="vertical">

        <com.highsoft.highcharts.core.HIChartView
            android:id="@+id/chart_pie"
            android:layout_width="wrap_content"
            android:layout_marginHorizontal="16dp"
            android:layout_height="@dimen/pie_height" />

        <com.highsoft.highcharts.core.HIChartView
            android:id="@+id/chart_line"
            android:layout_width="match_parent"
            android:layout_height="@dimen/line_height"
            android:layout_marginTop="@dimen/margin_medium" />

    </LinearLayout>
</ScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>`

Charts code:
`private fun setPieData(data: PieChartModel) {
val chartView: HIChartView = binding.chartPie
val options = HIOptions()

    val chart = HIChart()
    chart.type = "pie"
    chart.options3d = HIOptions3d()
    chart.options3d.depth = 45
    chart.options3d.enabled = true
    chart.options3d.alpha = 45
    options.chart = chart

    val title = HITitle()
    title.text = "${getString(R.string.content_total_)} ${data.totalViolations}"

    options.title = title

    val plotOptions = HIPlotOptions()
    plotOptions.pie = HIPie()
    plotOptions.pie.innerSize = 100
    plotOptions.pie.depth = 45

    val dataLabels = HIDataLabels()
    dataLabels.enabled = false

    plotOptions.pie.dataLabels = ArrayList(listOf(dataLabels))

    options.plotOptions = plotOptions

    val series = HIPie()
    series.name = getString(R.string.content_violations)
    val objectResolved =
        arrayOf<Any>(getString(R.string.content_resolved), data.totalResolved)
    val objectNotResolved =
        arrayOf<Any>(getString(R.string.content_not_resolved), data.totalNotResolved)
    val objectOverdue =
        arrayOf<Any>(getString(R.string.content_overdue), data.totalOverdue)
    series.data = ArrayList(
        listOf(
            objectResolved,
            objectNotResolved,
            objectOverdue
        )
    )
    series.colors = ArrayList(
        listOf(
            "#99ff98",
            "#feff98",
            "#FFAB98"
        )
    )
    series.showInLegend = true
    options.series = ArrayList(listOf(series))

    val credits = HICredits()
    credits.text = ""
    options.credits = credits

    val buttonOptions = HIButtonOptions()
    buttonOptions.enabled = false

    val exporting = HIExporting()
    exporting.enabled = false
    options.exporting = exporting

    chartView.options = options
}

private fun setLineData(data: LineChartModel) {
    val chartView = binding.chartLine
    val options = HIOptions()

    val chart = HIChart()
    chart.scrollablePlotArea = HIScrollablePlotArea()
    chart.scrollablePlotArea.minWidth = 2500
    chart.scrollablePlotArea.opacity = 0
    chart.height = 500
    options.chart = chart

    val title = HITitle()
    title.text = getString(R.string.title_violations_report)
    options.title = title

    val exporting = HIExporting()
    exporting.enabled = false
    options.exporting = exporting

    val xAxis = HIXAxis()
    xAxis.type = "linear"
    xAxis.width = 2400
    xAxis.categories = data.labels as ArrayList
    xAxis.gridLineWidth = 1
    options.xAxis = ArrayList(
        mutableListOf(xAxis)
    )

    val yAxis = HIYAxis()
    val yTitle = HITitle()
    yTitle.text = getString(R.string.title_violations_count)
    yAxis.title = yTitle
    options.yAxis = ArrayList(
        mutableListOf(yAxis)
    )

    val seriesOverdue = HISeries()
    seriesOverdue.type = "column"
    seriesOverdue.name = getString(R.string.content_overdue)
    seriesOverdue.data = data.overdue as ArrayList
    seriesOverdue.showInLegend = true
    seriesOverdue.color = HIColor.initWithRGBA(255, 171, 152, 1.0)

    val seriesResolved = HISeries()
    seriesResolved.type = "spline"
    seriesResolved.name = getString(R.string.content_resolved)
    seriesResolved.data = data.resolved as ArrayList
    seriesResolved.showInLegend = true
    seriesResolved.color = HIColor.initWithRGBA(153, 255, 152, 1.0)

    val seriesNotResolved = HISeries()
    seriesNotResolved.type = "spline"
    seriesNotResolved.name = getString(R.string.content_new_violations)
    seriesNotResolved.data = data.total as ArrayList
    seriesNotResolved.showInLegend = true
    seriesNotResolved.color = HIColor.initWithRGBA(75, 172, 255, 1.0)

    val legend = HILegend()
    legend.enabled = true

    val credits = HICredits()
    credits.text = ""
    options.credits = credits

    options.legend = legend

    options.series = ArrayList(listOf(seriesOverdue, seriesResolved, seriesNotResolved))
    chartView.options = options
}`

I would be glad to receive any hints on what I am doing wrong or what I should pay attention to
@MikolajMichalczak
Copy link
Contributor

Hello @Child0fTheSun!

I ran your code on a real device and couldn't reproduce this issue. Here are some potential solutions:

  1. Are you using an emulator for testing? If so, please try testing on a real device.
  2. Try setting the width of both charts to match_parent.
  3. I’m not sure how large your data set is—if it’s very large, try using a smaller sample for testing.

Additional steps:
4. Do you have hardware acceleration enabled or disabled in your manifest (android:hardwareAccelarated)?
5. Lastly, try using only a ScrollView instead of a CoordinatorLayout.

It's a somewhat unclear issue, so this is all I can suggest for now. I believe it might be related to the emulator, and I’d be glad to hear your feedback on this.

@Child0fTheSun
Copy link
Author

I am testing on a real device. Adding "android:hardwareAccelarated=true" to the manifest did not solve the problem. This problem can occur regardless of sample size, but varies from device to device. Right now I modified the code a little by adding chartView.setLayerType(View.LAYER_TYPE_SOFTWARE, null) and it solved the problem on some devices, but I also encounter this on some devices, for example Samsung Note 10

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