我有以下图表显示一些值。
我想在右侧隐藏/删除值,因为在左侧就足够了。
见下图:
代码如下:
public class MainActivity extends AppCompatActivity implements
OnChartValueSelectedListener{
private LineChart mDataLineChart;
private RelativeLayout mRelativeLayout;
private LineChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart);
// Set chart
setChart();
// add data
setData2(3, 155);
// ANIMATE CHART
animateChart();
}
private void setChart() {
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
////////////////////////////////
// SET DESCRIPTION COLOR
////////////////////////////////
mChart.setDescriptionColor(getResources().getColor(R.color.chart_desc_color));
////////////////////////////////
// BORDERS SURROUNDING THE CHART
////////////////////////////////
mChart.setDrawBorders(true);
mChart.setBorderColor(getResources().getColor(R.color.chart_border));
mChart.setBorderWidth(2);
////////////////////////////////
// CHART BG COLOR
////////////////////////////////
mChart.setBackgroundColor(getResources().getColor(R.color.chart_bg));
////////////////////////////////
// GRID BG COLOR
////////////////////////////////
mChart.setDrawGridBackground(true);
mChart.setGridBackgroundColor(getResources().getColor(R.color.chart_bg));
////////////////////////////////
// OTHER SETTINGS
////////////////////////////////
mChart.setDescription("");
mChart.setNoDataTextDescription("You need to provide data for the chart.");
// enable touch gestures
mChart.setTouchEnabled(true);
mChart.setDragDecelerationFrictionCoef(0.9f);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setHighlightPerDragEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(true);
}
private void setData2(int count, float range) {
////////////////////////////////
// X axis values (labels)
////////////////////////////////
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < count; i++) {
xVals.add((i) + " day");
}
////////////////////////////////
// Y axis values (value in linechart)
////////////////////////////////
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
float mult = range / 2f;
float val = (float) (Math.random() * mult) + 50;// + (float)
// ((mult *
// 0.1) / 10);
yVals1.add(new Entry(val, i));
}
////////////////////////////////
// SETTING FOR LINEAR LINE
////////////////////////////////
LineDataSet set1 = new LineDataSet(yVals1, "Pressure mm/Hg");
set1.setAxisDependency(AxisDependency.LEFT);
set1.setLineWidth(2f);
set1.setCircleSize(5f);
set1.setColor(getResources().getColor(R.color.chart_line_color));
set1.setCircleColor(getResources().getColor(R.color.chart_line_color));
set1.setFillColor(getResources().getColor(R.color.chart_line_color));
set1.setDrawCircleHole(true);
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
dataSets.add(set1); // add the datasets
////////////////////////////////
// SETTING FOR DATASET (FONT SIZE, )
////////////////////////////////
LineData data = new LineData(xVals, dataSets);
data.setValueTextColor(Color.BLACK);
data.setValueTextSize(9f);
////////////////////////////////
// SET WHOLE DATASET TO CHART
////////////////////////////////
mChart.setData(data);
}
private void animateChart() {
////////////////////////////////
// ANIMATION DURATION
////////////////////////////////
mChart.animateX(1000);
////////////////////////////////
// SET LEGEND BOTTOM DATA TEXT
////////////////////////////////
XAxis xAxis = mChart.getXAxis();
xAxis.setTextSize(12f);
xAxis.setTextColor(Color.BLACK);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setSpaceBetweenLabels(1);
}
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
Log.i("Entry selected", e.toString());
}
@Override
public void onNothingSelected() {
Log.i("Nothing selected", "Nothing selected.");
}
}
我试图在Github上搜索文档:
https://github.com/PhilJay/MPAndroidChart/wiki/The-Axis
但没有运气。
我如何从右边删除值?
非常感谢您的任何建议。
答案 0 :(得分:14)
YAxis yAxisRight = mChart.getAxisRight();
yAxisRight.setEnabled(false);
将此代码放在setChart();
上