我正在使用MPAndroidChart库发行版v2.我正在尝试显示3个条形图,数据来自数据库.不幸的是,不是看到3个条形数据,而是用相同的结果查看它们.查看截图.谢谢你的帮助.
int [] x = {1,2,3};
Cursor c = db.rawQuery(sql, null);
int count = c.getCount();
float value1 ;
float value2 ;
float value3 ;
String[] mesi = new String[count];
for(int n=0; n<count; n++) {
c.moveToNext();
mesi[n]= c.getString(0);
value1 = c.getFloat(1);
value2 = c.getFloat(2);
value3 = c.getFloat(3);
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i <x.length; i++) {
xVals.add(x.length + " " + mChart.getUnit());
}
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
ArrayList<BarEntry> …Run Code Online (Sandbox Code Playgroud) 我正在使用MPAndroidChart库,尝试自定义Stacked Bars.目标是显示两种货币之间的差异.所以假设这个例子是1月份.货币#1 = 8; 货币#2 = 12
这个想法是在同一个条形图中显示两个值,而不是将2个值(8 + 12)相加以使值8"在前面"而值12"在后面".因此,条形图的总高值是最大值.
我尝试这样做,扩展BarEntry类,而不是计算总和,只需设置最大值.但我现在只看到一个酒吧(价值= 12的酒吧)
你知道这种逻辑是否得到支持吗?有什么建议?
我正在使用名为MPAndroidChart的图表库,我对它非常满意.但是,我想绘制一条粗垂直线(作为背景,而不是数据)作为线图中间的指示器.我怎样才能做到这一点?
最好的祝福.
我需要改变Y轴的增量值.
我正在使用此代码设置min和max:
YAxis rightYAxis = chart.getAxisRight();
rightYAxis.setAxisMaxValue(180);
rightYAxis.setAxisMinValue(0);
Run Code Online (Sandbox Code Playgroud)
它给出了右Y轴的这个视图:

Y轴显示[0,30,60,...,180]因此这里的增量为30.但我需要设置增量等于10.所以我想看[0,10,20,...,180].
我认为这mChart.setVisibleYRange(10, YAxis.AxisDependency.RIGHT);对我有帮助,但事实并非如此.同样的rightYAxis.mAxisRange = 10;.
是否可以设置它?这将非常有用.
我怎样才能做到这一点?我试图在Xcode中找到方法,但我不能 - 在android文档中他们有不同的名字
我有这样的哈希映射
LinkedHashMap<String, String> hash = new LinkedHashMap<>();
hash.put("2015-05-03", 100);
hash.put("2015-05-04", 110);
hash.put("2015-05-05", 90);
hash.put("2015-05-06", 40);
Run Code Online (Sandbox Code Playgroud)
我想通过MPAndroidChart设计一个LineChart,但它不工作,图表无效,没有任何显示!似乎我的代码无效.
这是我的代码:
private void setChartData(LinkedHashMap<String, String> lastMonthMediaLikes)
{
ArrayList<String> xVals = new ArrayList<>();
for(Map.Entry<String, String> entry : lastMonthMediaLikes.entrySet())
{
xVals.add(entry.getKey());
}
ArrayList<Entry> vals1 = new ArrayList<>();
int i = 0;
for(Map.Entry<String, String> entry : lastMonthMediaLikes.entrySet())
{
vals1.add(new Entry(Float.valueOf(entry.getValue()), i));
i++;
}
// create a dataset and give it a type
LineDataSet set1 = new LineDataSet(vals1, "DataSet 1");
set1.setDrawCubic(true);
set1.setCubicIntensity(0.2f);
//set1.setDrawFilled(true);
set1.setDrawCircles(false);
set1.setLineWidth(1.8f);
set1.setCircleSize(4f); …Run Code Online (Sandbox Code Playgroud) 我正在使用MPAndroidChart库.我正在使用CustomValueFormatter格式化Float值,使其精度为1.
CustomValueFormatter代码:
public class CustomYAxisValueFormatter implements YAxisValueFormatter {
private DecimalFormat mFormat;
public CustomYAxisValueFormatter() {
mFormat = new DecimalFormat("###,###,###,##0.0"); // sets precision to 1
}
@Override
public String getFormattedValue(float value, YAxis yAxis) {
return mFormat.format(value);
}
}
Run Code Online (Sandbox Code Playgroud)
我将格式化程序设置为y轴.
设置格式化程序:
YAxis yAxis = lineChart.getAxisLeft(); //show left y-axis line
yAxis.setValueFormatter(new CustomYAxisValueFormatter()); // set value formatter to format y-values.
Run Code Online (Sandbox Code Playgroud)
因此,默认情况下会创建setValueFormatter(YAxisValueFormatter)上述格式化程序(CustomYAxisValueFormatter).
问题是在缩放时无法重新创建CustomYAxisValueFormatter,从而导致重复的y值.
是否可以创建一个基于缩放级别更改值精度的CustomValueFormatter?
我有一些RadarChart标签问题.具体来说,如果我使用长文本(例如15-20个字符),并且可用空间不是太大,则图表会折叠并且标签位于折叠图表内(但显然有更多可用空间).
我试图用ValueFormatter标签轴截断标签,如果长度超过5个字符,但正如我所见,图表大小计算基于完整标签文本,因为图表折叠方式与我之前描述的相同.
XAxis xAxis = radarChart.getXAxis();
xAxis.setValueFormatter(new XAxisValueFormatter() {
@Override
public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
return original.length() > 5 ? original.substring(0, 5) + "…" : original;
}
});
Run Code Online (Sandbox Code Playgroud)
这里有一些图片来澄清问题.图表显示在CardViews 内部,正如您所看到的,所有侧面都有足够的空间.前两张图片是用ValueFormatter套装拍的,后两张是没有它的.
要做的事情: 使用库绘制时间序列折线图,其中x轴时间戳不是等距的.
样本数据:
1467886121:325
1467886153:326
1467886185:325
1467886248:326
1467886280:326
1467886311:326
1467886343:327
1467886375:327
1467886406:327
1467886438:328
1467886529:328
1467886561:327
1467886593:327
1467886625:326
1467886659:327
1467886692:326
1467886725: 326
注意: LHS值是UNIX时间戳,RHS值是相应时间戳的数据点.时间戳不是等距的,因此它们应根据两者之间的时间间隔进行间隔.最近,MPAndroidChart引入了这个功能[github:link]
在这里,他们似乎正在添加相隔一小时的新值.我想根据UNIX时间戳中的时间间隔添加值.
我该怎么做?
只是希望这里的人可以解释如何反转HorizontalBarChart的顺序,该顺序显示在MPAndroidChart的屏幕快照中(因此,不是44.0位于顶部,而是底部)。
下面的代码显示了如何创建用于生成HorizontalBarChart的BarDataSet。
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range);
yVals1.add(new BarEntry(i * spaceForBar, i * 4));
}
BarDataSet set1 = new BarDataSet(yVals1, "DataSet 1");
Run Code Online (Sandbox Code Playgroud)
我试图反转for循环,以便以相反的方式添加数据集,但似乎产生了相同的HorizontalBarChart。
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = count-1; i >= 0; i--) {
float val = (float) (Math.random() * range);
yVals1.add(new BarEntry(i * spaceForBar, i * 4));
}
BarDataSet set1 = new BarDataSet(yVals1, "DataSet 1");
Run Code Online (Sandbox Code Playgroud)
希望有人能够向我展示一种反转此图表顺序的方法。 …