我的XAxis值未对齐。我应该修改什么设置?
到目前为止,我的代码中包含以下内容.setLabelsToSkip因为我使用的是3.0.1版而无法正常工作。
private void setData() {
ArrayList<BarEntry> entries = new ArrayList<>();
String labels[]=new String[5];
for (Cars c : values) {
if (c.getX()==1){
labels[0] = "Engine 1";
}
if (c.getX()==2){
labels[1] = "Engine 2";
}
if (c.getX()==3){
labels[2] = "Engine 3";
}
if (c.getX()==4){
labels[3] = "Engine 4";
}
if (c.getX()==5){
labels[4] = "Engine 5";
}
entries.add(new BarEntry((float) c.getX(), ((float) c.getY()),labels));
}
BarDataSet set1;
if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
set1.setValues(entries);
mChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));
//set1.setValueFormatter(new LabelFormatter(labels));
//mChart.getXAxis().setValueFormatter(new BarValueFormatter(set1));
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(entries, "Engine Types");
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.JOYFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
set1.setColors(colors);
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
mChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));
//mChart.getXAxis().setValueFormatter(new LabelFormatter(labels));
//mChart.getXAxis().setValueFormatter(new BarValueFormatter(set1));
BarData data = new BarData(dataSets);
data.setValueTextSize(50f);
data.setValueTextColor(Color.WHITE);
data.setValueTypeface(mTfLight);
mChart.setData(data);
}
}
这是我的LabelFormatter类:
mChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));
这是我的主要活动setdata方法:
WHERE
在我的主要活动中,我这样使用它:
Public Function LoadAttachments(useridparam As Integer) As Long
'(strPath As String, Optional StrPattern As String) As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset2
Dim rsA As DAO.Recordset2
Dim fld As DAO.Field2
Dim strFile As String
'Get the database, recordset, and attachment field
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM tblAttachments WHERE UserID=" & useridparam)
Set fld = rst("Fieldatttachment")
'...same logic (syntax fixed)...
End Function
Private Sub Fieldatttachment_Click()
Dim result As Long
result = LoadAttachments(Forms!frmAttachments!UserId)
Msgbox "Successfully uploaded " & result & " files!", vbInformation, "SUCCESSFUL UPLOAD"
End Sub
答案 0 :(得分:0)
如果要将xAxis标签与每个条形图的中心对齐,请将setCenterAxisLabels属性设为false
xAxis.setCenterAxisLabels(false);