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

tree chart is showing on activity but not showing in fragment #257

Open
hrgdeveloper opened this issue Jul 31, 2022 · 1 comment
Open

tree chart is showing on activity but not showing in fragment #257

hrgdeveloper opened this issue Jul 31, 2022 · 1 comment

Comments

@hrgdeveloper
Copy link

hrgdeveloper commented Jul 31, 2022

hello , i am using any chart trial version 1.1.2
this code is working on activity and the chart is showing but when i use exactly same code in a fragment that is inside a viewpager a white screen is showing whit out any chart trial version lable and nothing show up. i have logged data and evry thing is okey . i dont see any log message from any chart in log cat

if i update library to 1.1.3 or 1.1.4 the chart wont show up even on activity . even with your sample code .
https://github.com/AnyChart/AnyChart-Android/blob/master/sample/src/main/java/com/anychart/sample/charts/TreeMapChartActivity.java

this is the code that i am using on activity and chart is showing . but on the fragment after getting data from live data i do the same thing and only a white screen is showing

`class TreeChartActivity : BaseActivityNew() {

private val marketStatVM by viewModels<MarketStatViewModel>()
var marketStats = ArrayList<MarketStat>()



override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    marketStatVM.irtMarketsLiveData.observe(this) {
        marketStats.clear()
        marketStats.addAll(it)
        val treeMap: TreeMap = AnyChart.treeMap()
        val data: MutableList<DataEntry> = ArrayList()
        data.add(CustomTreeDataEntry("Markets", "Markets By Value", "Markets"))
        marketStats.forEach {
            val price =formatDoubleNew(it.latest,Precisions.getAmountPreciousByCurrency(it.srcCurrency),DoubleType.AMOUNT,true)
            data.add(CustomTreeDataEntry(it.srcCurrency,"Markets",it.srcCurrency.uppercase()+"/"+it.dstCurrency.uppercase(),
                it.volumeDst, it.dayChange,getColorByPercent(it.dayChange,
                ),   price
             ))
        }
        treeMap.data(data, TreeFillingMethod.AS_TABLE)
        treeMap.colorScale()
        treeMap.padding(0, 0, 50.0, 0)
        treeMap.maxDepth(2.0)
        treeMap.hovered().fill("#bdbdbd", 0.8)
        treeMap.selectionMode(SelectionMode.NONE)

        treeMap.labels().useHtml(true)
        treeMap.labels().fontColor("#121212")
        treeMap.labels().fontSize(12.0)

        treeMap.labels().format(
            "function() {\n" +
                    "var name = this.getData('product')\n"+
                    "var price = this.getData('extra')\n"+
                    "var value = this.getData('value')\n"+
                    "var all = name + '-'+price + '-' + value+'%'\n"+
                    "      return all;\n" +
                    "    }"
        )

        treeMap.headers().format(
            ("function() {\n" +
                    "    return this.getData('product');\n" +
                     "  }")
        )

        treeMap.tooltip()
            .useHtml(true)
            .titleFormat("function() {\n" +
                    "       return this.getData('extra');\n" +
                    "    }")
            .format(
                ("function() {\n" +
                        "       return this.getData('extra');\n" +
                        "    }")
            )

        binding.anyChart.setChart(treeMap)

    }

}

private fun getColorByPercent(percent:Float) : String{
    when {
        percent < -5 -> {
            return "#BE464E"
        }
        percent < -4 && percent >=-5 ->{
            return "#EE5862"
        }
        percent < -3 && percent >=-4 ->{
            return "#F17981"
        }
        percent < -2 && percent >=-3 ->{
            return "#F49AA0"
        }

        percent < -1 && percent >=-2 ->{
            return "#F8BCC0"
        }

        percent < 0 && percent >=-1 ->{
            return "#FBDDDF"
        }
        percent == 0f -> {
            return "#b3b3be"
        }
        percent > 0 && percent <=1 ->{
            return "#D2F3F1"
        }
        percent > 1 && percent <=2 ->{
            return "#A5E7E3"
        }
        percent > 2 && percent <=3 ->{
            return "#79DCD5"
        }
        percent > 3 && percent <=4 ->{
            return "#4CD0C7"
        }
        percent > 4 && percent <=5 ->{
            return "#20C5BA"
        }
        percent > 5 ->{
            return "#199D94"
        }else-> {
        return "#b3b3be"
    }

    }
}

override fun getViewBinding(): ActivityTreeChartBinding {
    return  ActivityTreeChartBinding.inflate(layoutInflater)
}

override fun getToolbar(): Toolbar? {
    return null
}

 class CustomTreeDataEntry : TreeDataEntryCustom {
    internal constructor(
        id: String?,
        parent: String?,
        product: String?,
        size : Number,
        value: Number?,
        fill:String,
        extra:String
    ) : super(id, parent,size, value) {
        setValue("product", product)
        setValue("fill", fill)
        setValue("extra", extra)
    }

    internal constructor(id: String?, parent: String?, product: String?) : super(id, parent) {
        setValue("product", product)
    }
}

}`

@black-pwq
Copy link

I got stuck for this too. Tree chart will show the first time i enter the fragment. But when i navigate to another fragment and back to it, it may possibly disappear (so strange) and only left with the watermark. However, when i back to the home screen (making the activity stopped) and reenter the app it shows again. I am using tree chart to show file size like a file explorer. What makes me quite confused is that it POSSIBLY shows white screen and sometimes works.

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