问题描述
我使用 MPAndroidChart库。我想在MPAndroidChart定制的传说。在MPAndroidChart图书馆中,我试图让传说中的位置。由下式给出code legend.setPosition(LegendPosition.BELOW_CHART_CENTER),但无法做到这一点。我必须设置的传说,如图下图
I am using MPAndroidChart library. I want customize legends in MPAndroidChart. In MPAndroidChart library i tried to set the position of legends. by given code legend.setPosition(LegendPosition.BELOW_CHART_CENTER) but unable to do it. I have to set legends as shown in following image
帮助将AP preciate
help will be appreciate
推荐答案
请认准给出答案MPAndroidChart - 传奇标签被切断。我已经按照你的问题已经给出了答案。寻找给定的code这一定会帮助你。你必须按照下面的步骤来实现他们的传奇色彩和标签定制传说:
Please look for the given answer MPAndroidChart - Legend labels are being cut off. I have already provided the answer according to your problem.Look for given code which will definitely help you.You will have to implement customized legends with their legends colours and labels by following the steps below:
第1步
Legend legend = mChart.getLegend();
第2步
int colorcodes[] = legend.Colors();
步骤3
for (int i = 0; i < legend.Colors().length-1; i++) {
.....
.....
}
步骤4
然后,你将不得不采取一种布局水平或垂直,并获得传说色彩codeS和传说的标签,并根据传说长度创建布局和标签。 code样本如下:
Then you will have to take one layout horizontal or vertical and get legends color codes and legends label and according to legends length create layout and label. Code sample is given below:
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, 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);
和在此之后添加(已创建在运行时子布局)的主要版面。
And after this add your (child layout which you have created at runtime ) to the main layout.
这篇关于MPAndroidChart传说定制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!