帮助将是欣赏
解决方法 请查找给定答案 MPAndroidChart – Legend labels are being cut off.我已经根据您的问题提供了答案.寻找给定代码肯定会帮助你.
您必须按照以下步骤使用其图例颜色和标签实现自定义图例:
步骤1
Legend legend = mChart.getLegend();
第2步
int colorcodes[] = legend.colors();
第3步
for (int i = 0; i < legend.colors().length-1; i++) { ..... ..... }
第4步
然后你必须采取水平或垂直的一个布局,并获得图例颜色代码和图例标签,并根据图例长度创建布局和标签.代码示例如下:
linearLayout.LayoutParams parms_left_layout = new linearLayout.LayoutParams( LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT); parms_left_layout.weight = 1F; linearLayout left_layout = new linearLayout(context); left_layout.setorIEntation(linearLayout.HORIZONTAL); left_layout.setGravity(Gravity.CENTER); left_layout.setLayoutParams(parms_left_layout); linearLayout.LayoutParams parms_legen_layout = new linearLayout.LayoutParams( 20,20); parms_legen_layout.setmargins(0,20,0); linearLayout legend_layout = new linearLayout(context); legend_layout.setLayoutParams(parms_legen_layout); legend_layout.setorIEntation(linearLayout.HORIZONTAL); legend_layout.setBackgroundcolor(colorcodes[i]); left_layout.addVIEw(legend_layout); TextVIEw txt_unit = new TextVIEw(context); txt_unit.setText(legend.getLabel(i)); left_layout.addVIEw(txt_unit); linearLayout.LayoutParams parms_mIDdle_layout = new linearLayout.LayoutParams( LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT); parms_mIDdle_layout.weight = 1F; linearLayout mIDdle_layout = new linearLayout(this); mIDdle_layout.setorIEntation(linearLayout.HORIZONTAL); mIDdle_layout.setGravity(Gravity.CENTER); mIDdle_layout.setLayoutParams(parms_mIDdle_layout); TextVIEw txt_leads = new TextVIEw(this); txt_leads.setText("450"); mIDdle_layout.addVIEw(txt_leads); linearLayout.LayoutParams parms_right_layout = new linearLayout.LayoutParams( LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT); parms_right_layout.weight = 1F; linearLayout right_layout = new linearLayout(this); right_layout.setorIEntation(linearLayout.HORIZONTAL); right_layout.setGravity(Gravity.CENTER); right_layout.setLayoutParams(parms_right_layout); TextVIEw txt_leads_percentage = new TextVIEw(this); txt_leads_percentage.setText(munit_percentage_List.get(i) + ""); right_layout.addVIEw(txt_leads_percentage); childlayout.addVIEw(left_layout); childlayout.addVIEw(mIDdle_layout); childlayout.addVIEw(right_layout);
然后将您(在运行时创建的子布局)添加到主布局.
总结以上是内存溢出为你收集整理的MPAndroidChart图例定制全部内容,希望文章能够帮你解决MPAndroidChart图例定制所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)