【发布时间】:2015-09-01 02:10:38
【问题描述】:
这是我运行它时的家庭活动代码,它只是一个小尺寸的箱形图,所有内容都压缩在一个非常小的图表中。请帮助我如何让我的图表更大
package com.example.frendzy.iassist;
import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RelativeLayout;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.LineData;
public class homeActivity extends ActionBarActivity {
private RelativeLayout myLayout;
private LineChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
myLayout = (RelativeLayout) findViewById(R.id.myLayout);
//create line chart
mChart = new LineChart(this);
//add to mylayout
myLayout.addView(mChart);
//customize line chart
mChart.setDescription("");
mChart.setNoDataTextDescription("No data for the moment");
//enable value highlighting
mChart.setHighlightEnabled(true);
//enable touch gestures
mChart.setTouchEnabled(true);
//we want also enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);
//enable pinch zoom to avoid scaling x and y axis separately
mChart.setPinchZoom(true);
//alternative background color
mChart.setBackgroundColor(Color.LTGRAY);
//now we work on data
LineData data=new LineData();
data.setValueTextColor(Color.WHITE);
//add data to line chart
mChart.setData(data);
//get legend object
Legend l = mChart.getLegend();
//customize legend
l.setForm(Legend.LegendForm.LINE);
l.setTextColor(Color.WHITE);
XAxis x1 = mChart.getXAxis();
x1.setTextColor(Color.WHITE);
x1.setDrawGridLines(false);
x1.setAvoidFirstLastClipping(true);
YAxis y1 = mChart.getAxisLeft();
y1.setTextColor(Color.WHITE);
y1.setAxisMaxValue(120f);
y1.setDrawGridLines(true);
YAxis y12 = mChart.getAxisRight();
y12.setEnabled(false);
}
【问题讨论】:
-
在这里查看。stackoverflow.com/a/36593297/6021284我已经为此发布了答案。
标签: android linechart mpandroidchart