这是我的家庭活动代码,当我运行它时,它只是一个小尺寸的框图,所有的内容都被压缩在一个非常小的图表中。请告诉我如何让我的图表更大
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);
} 发布于 2015-09-03 04:32:42
我也有同样的问题。已尝试以编程方式将LineChart的LayoutParams设置为match_parent,但不起作用。在我的示例中,我从布局xml中删除了LineChart视图,并将其替换为以下代码:
LineChart chart = new LineChart(context);
setContentView(chart);在您的情况下,您应该删除:
myLayout = (RelativeLayout) findViewById(R.id.myLayout);
//add to mylayout
myLayout.addView(mChart);EDIT:如果您正在使用片段,则在按back时将收到一个错误。
片段的临时修复:
@Override
public void onStop() {
super.onStop();
getActivity().setContentView(R.layout.activity_main);
}发布于 2015-09-01 12:42:41
你可以尝试很多方法:
在添加linearChart之前检查
如果你看到我的猜测,我很抱歉,但我现在没有一台合适的笔记本电脑来测试你的代码:(
发布于 2015-09-23 06:14:58
我也有同样的问题,但我通过替换
mainLayouts.addView(mChart)通过
setContentView(mChart);一定要试一试。这对我很管用。祝你编码愉快!
https://stackoverflow.com/questions/32322511
复制相似问题