如何在android中使用mpchart库设置图表外的矩形框?
我试图在android中使用MPchart库绘制一个图形。 但我无法在图表外显示背景色为绿色的矩形框,如图所示: 我尝试使用MPchart库的以下方法:如何在android中使用mpchart库设置图表外的矩形框?,android,Android,我试图在android中使用MPchart库绘制一个图形。 但我无法在图表外显示背景色为绿色的矩形框,如图所示: 我尝试使用MPchart库的以下方法: setDrawGridBackground(true); setDrawGridBackground(true) setGridBackgroundColor(Color.BLUE) 它不是设置图表外部的颜色,而是设置图表的背景色,如下图所示: 请提供任何建议,以便我可以在xml文件中的图1中获得预期的图形输出。将背景属性添加到条形图元素 &
setDrawGridBackground(true);
setDrawGridBackground(true)代码>
setGridBackgroundColor(Color.BLUE)代码>
请提供任何建议,以便我可以在xml文件中的图1中获得预期的图形输出。将背景属性添加到条形图元素
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/bar_chart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00AAA7"/>
输出看起来像在图像链接中
我使用了mpchart库'com.github.PhilJay:MPAndroidChart:v2.2.4'
//对于引用,我使用了静态值
//X坐标
ArrayList sales=新建ArrayList();
新增(新巴伦特里(900f,0));
新增(新巴伦特里(1150f,1));
新增(新巴伦特里(780f,2));
新增(新巴伦特里(1050f,3));
新增(新巴伦特里(1180f,4));
新增(新巴伦特里(1200f,5));
新增(新巴伦特里(1160f,6));
新增(新巴伦特里(1220f,7));
新增(新巴伦特里(1100f,8));
//Y坐标
ArrayList月=新建ArrayList();
月份。添加(“六月”);
月。添加(“7月”);
月。添加(“8月”);
添加月份(“9月”);
月。添加(“10月”);
月份。添加(“11月”);
月份。添加(“12月”);
BarDataSet BarDataSet=新的BarDataSet(销售额,“总销售额”);
//生动活泼
barChart.animateY(2000年);
//定色
设置颜色(ColorTemplate.Colorbid_COLORS);
BarData BarData=新的BarData(月,BarData集);
条形图.设置数据(barData);
//布局中的xml
希望这个答案能对你有所帮助。
输出:
这是mpchart库,用于“com.github.PhilJay:MPAndroidChart:v3.0.2”如何显示将x轴描述为图表外月份的标签签出以上答案(刚刚编辑)以将月份设置为Y轴(如图所示)。我没有尝试设置月份x轴,让我检查一下@priyahow根据PhilJay(库所有者)字符串(缩放?)标签在mpchart@Mohsin中添加缩放标签当前默认情况下不受支持。您已经在图表外添加了文本视图。查看PhilJay在github@priya上给出的答案
setDrawGridBackground(true);
//for refrence I used static values
// X co-ordinate
ArrayList sales=new ArrayList();
sales.add(new BarEntry(900f,0));
sales.add(new BarEntry(1150f,1));
sales.add(new BarEntry(780f,2));
sales.add(new BarEntry(1050f,3));
sales.add(new BarEntry(1180f,4));
sales.add(new BarEntry(1200f,5));
sales.add(new BarEntry(1160f,6));
sales.add(new BarEntry(1220f,7));
sales.add(new BarEntry(1100f,8));
// Y co-ordinate
ArrayList<String> month=new ArrayList<>();
month.add("June");
month.add("July");
month.add("Aug.");
month.add("Sept.");
month.add("Oct.");
month.add("Nov.");
month.add("Dec.");
BarDataSet barDataSet=new BarDataSet(sales,"Total Sales");
//animate
barChart.animateY(2000);
//set colors
barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
BarData barData=new BarData(month,barDataSet);
barChart.setData(barData);
//xml in layout
<com.github.mikephil.charting.charts.BarChart
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bar_chart">
</com.github.mikephil.charting.charts.BarChart>