Skip to content

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

@hrgdeveloper

Description

@hrgdeveloper

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)
    }
}

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions