gpt4 book ai didi

安卓 : MPAndroidChart how to remove values on right side in chart?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:40:49 27 4
gpt4 key购买 nike

我有以下显示一些值的图表。

我想隐藏/删除右侧的值,因为左侧就足够了。

见下图:

enter image description here

代码如下:

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

但运气不好。

请问如何删除右边的值?

非常感谢您的任何建议。

最佳答案

YAxis yAxisRight = mChart.getAxisRight();
yAxisRight.setEnabled(false);

将此代码放在您的 setChart() 上;

关于安卓 : MPAndroidChart how to remove values on right side in chart?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33873075/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com