Legends get cut off with pie chart in MPAndroidChart?

文章推薦指數: 80 %
投票人數:10人

EquityFragment"> Andthisiscode privatefuncreateChart(chartData:List){ valpieEntry=chartData.map{PieEntry(it.equity,it.name)} valrnd=Random() valcolors=mutableListOf() for(iinchartData.indices){ colors.add(Color.argb(255,rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256))) } valdataSet=PieDataSet(pieEntry,getString(R.string.equity_title)) dataSet.colors=colors binding.pieChart.data=PieData(dataSet) binding.pieChart.isDrawHoleEnabled=false binding.pieChart.legend.isWordWrapEnabled=true binding.pieChart.invalidate() } thisistheUIigetindevice androidpie-chartmpandroidchart Share Improvethisquestion Follow askedNov2,2021at7:00 WISHYWISHY 9,8872222goldbadges9191silverbadges164164bronzebadges Addacomment  |  2Answers 2 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 0 Thetextoflegendsaretoobigtobefitinsidethegraph.Onewayistokeepthemoutsidethegraph. Thefollowingattributecanbeaddedtoachievethisjob: setDrawInside() Pleaseusethiscode: Legendl=pieChart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); l.setXEntrySpace(4f); l.setYEntrySpace(0f); l.setWordWrapEnabled(true); Thiswillsetthelegendoutsidethegraph. Share Improvethisanswer Follow answeredNov2,2021at7:10 AbhishekDuttAbhishekDutt 1,08455goldbadges1313silverbadges2121bronzebadges 1 doesn'twork.triedthis – WISHY Nov2,2021at8:07 Addacomment  |  0 Iendedupdoinglikethiswiththehelpofflexboxlayout XML Legendlayout Kotlincode privatefuncreateChart(chartData:List){ valpieEntry=chartData.map{PieEntry(it.equity)} valrnd=Random() valcolors=mutableListOf() for(iinchartData.indices){ colors.add(Color.argb(255,rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256))) } valdataSet=PieDataSet(pieEntry,getString(R.string.equity_title)) dataSet.colors=colors dataSet.valueTextSize=14f dataSet.setDrawValues(false) dataSet.valueTextColor=ContextCompat.getColor(requireContext(),android.R.color.white) binding.pieChart.data=PieData(dataSet) binding.pieChart.isDrawHoleEnabled=false binding.pieChart.description=Description().apply{text=""} binding.pieChart.invalidate() binding.pieChart.animateY(1400,Easing.EaseInOutQuad); binding.pieChart.legend.isEnabled=false creatChartLabels(colors,chartData) } privatefuncreatChartLabels(colors:List,chartData:List){ for(iinchartData.indices){ valview=ItemLegendBinding.inflate(layoutInflater) view.legendBox.setBackgroundColor(colors[i]) view.legendTitle.text=chartData[i].name binding.chartLabels.addView(view.root) } } output Share Improvethisanswer Follow answeredNov2,2021at10:19 WISHYWISHY 9,8872222goldbadges9191silverbadges164164bronzebadges Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedandroidpie-chartmpandroidchartoraskyourownquestion. TheOverflowBlog IspenttwoyearstryingtodowhatBackstagedoesforfree Aserialentrepreneurfinallyembracesopensource(Ep.486) FeaturedonMeta PlannedmaintenancescheduledforWednesday,21September,00:30-03:00UTC... RecentColorContrastChangesandAccessibilityUpdates Revieweroverboard!Orarequesttoimprovetheonboardingguidancefornew... ShouldIexplainotherpeople'scode-onlyanswers? Related 4 callfragmentswhenclickingRecyclerViewitemandshowthembothinthesameactivity 0 RecyclerviewinsideCoordinatorlayout 2 CansomebodyshowmewhyListViewisn'tshowing? 2 howcanweusev7widgetcodeinandroidstudio?.howtousev7widgetinandroidx? 2 Greytextappearwhitewithoutlineinandroiddevice 0 HowtoaddaTabItembyactivity? HotNetworkQuestions Whyputa10kresistorbetweenVUSBandGND? Anumbertheoryproblemwherepiappearssurprisingly InwhichtournamentdidKarpovplayhisfirstmovewithwhitepiecesandofferadraw? Dobasiclandcardsenterthebattlefieldtapped? SciencefictionshortstoryinwhichEinsteinisclonedbutshowsnointerestinmuchexceptplayinghisviolin Whydon'tcarshavecircuitbreakersinsteadoffuses? Chessetiquette:Carlsenwithdrawingfromthetournament Howtopronounce"Gröbner"? ProtocolinLatex Howtoproperlyacknowledgeanoldfamousmathematicianinmyarticle? Whatsthedifferencebetween客户反馈vs客户评论vs用户评论? WhywasJWSTcancelledin2011? Howtoplayasadual-wieldingmonk? Isitokaythatpartofthepowerjackisoutsidethedevice? Centerofawirenutholdingneutralwiresisburned,butitdoesn'tseemloose Whatexactlyismeantbyisotropicandanisotropicwithwordvectors 110.15High-LegMarking IsEPSGdefinedseparatelyforeachgeometrycolumn? IntheRoEforapentest,doyouincludealistofalltools? Whereisthereactionforceofanobjectthathasjustflungoutfromacircularmotion? ShouldIbechangingtemperatureminandmaxorreactionspeedifIwantmyflamestogohigher? St_Splitnotsplitlinebypoint Whyissendingtroopsdifferentfromsendingmilitaryequipment? Scholarshipsbyemailingprofessors morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?