因此,我正在使用很棒的MPAndroid图表库来制作一个简单的LineChart。我能够使用GitHub上的示例项目大量定制它。
问题是,当我将它移到我自己的代码中时,某些方法不再能够解决:
特别是mlineChart.setExtraOffsets()和mlineChart.setAutoScaleminMaxEnabled()。可能还有其他的,但这是我注意到的仅有的两个。
不过,其他一切都很好。知道为什么我不能访问这两个方法吗?我应该挖掘什么才能更多地了解为什么会这样?
public class MyFragment extends Fragment {
private LineChart mLineChart;
// stuff here
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// stuff here
// Creating numbers line chart for candidate
LineChart numChart = (LineChart)view.findViewById(R.id.numbersLineChart);
setNumChart(numChart, mObject.getNums());
// stuff here
}
public void setNumChart(LineChart lineChart, List<Integer> nums){
mLineChart = lineChart;
mLineChart.setDrawGridBackground(false);
// no description text
mLineChart.setDescription("");
mLineChart.setNoDataTextDescription("You need to provide data for the chart.");
// enable value highlighting
mLineChart.setHighlightEnabled(true);
// enable touch gestures
mLineChart.setTouchEnabled(true);
// enable scaling and dragging
mLineChart.setDragEnabled(false);
mLineChart.setScaleEnabled(false);
// if disabled, scaling can be done on x- and y-axis separately
mLineChart.setPinchZoom(false);
// create a custom MarkerView (extend MarkerView and specify the layout to use for it)
MyMarkerViewv2 mv = new MyMarkerViewv2(getActivity(), R.layout.custom_marker_view, mLineChart);
// set the marker to the chart
mLineChart.setMarkerView(mv);
// disable all axes lines and labels
YAxis leftAxis = mLineChart.getAxisLeft();
leftAxis.setEnabled(false);
mLineChart.getAxisRight().setEnabled(false);
XAxis bottomAxis = mLineChart.getXAxis();
bottomAxis.setEnabled(false);
// add data
setLineChartData(nums);
//THIS METHOD CANNOT BE RESOLVED********************
mLineChart.setExtraOffsets(30f,50f,30f,0f);
// get the legend (only possible after setting data)
Legend l = mLineChart.getLegend();
l.setEnabled(false);
mLineChart.invalidate();
}
public void setLineChartData(List<Integer> nums){
//create xVariables aka strings of the months
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < nums.size(); i++) {
xVals.add(Month.getMonthfromIndex(i).getAbbrev());
}
//add corresponding numbers
ArrayList<Entry> yVals = new ArrayList<Entry>();
for (int i = 0; i < nums.size(); i++) {
yVals.add(new Entry(nums.get(i), i));
}
// create a dataset and give it a type
LineDataSet set1 = new LineDataSet(yVals, "DataSet");
set1.setColor(Color.BLACK);
set1.setCircleColor(Color.BLACK);
set1.setLineWidth(0.75f);
set1.setDrawCircles(true);
set1.setDrawValues(false);
set1.setCircleSize(1.75f);
set1.setDrawCircleHole(false);
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets
LineData data = new LineData(xVals, dataSets);
// set data
mLineChart.setData(data);
}
// stuff here
class MyMarkerViewv2 extends MarkerView {
private TextView markerContent;
private LineChart mChart;
public MyMarkerViewv2(Context context, int layoutResource, LineChart lChart) {
super(context, layoutResource);
mChart = lChart;
markerContent = (TextView) findViewById(R.id.markerContent);
}
// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry e, int dataSetIndex) {
if (e instanceof CandleEntry) {
CandleEntry ce = (CandleEntry) e;
List<String> months = mChart.getLineData().getXVals();
markerContent.setText(months.get(e.getXIndex() % 12) + "\n" + Utils.formatNumber(ce.getHigh(), 0, true) + "%");
} else {
List<String> months = mChart.getLineData().getXVals();
markerContent.setText(months.get(e.getXIndex() % 12) + "\n" + Utils.formatNumber(e.getVal(), 0, true) + "%");
}
}
@Override
public int getXOffset() {
// this will center the marker-view horizontally
return -(getWidth() / 2);
}
@Override
public int getYOffset() {
// this will cause the marker-view to be above the selected value
return -getHeight();
}
}
我还将LineChart与其他元素包装在垂直的LinearLayout中,并将整个内容包装在ScrollView中。不确定这是否是导致问题的原因。
没关系,我想通了。这是因为Maven和Gradle下载的库与网站上的示例项目中包含的库不完全相同。
我安装了Android Studio并构建了一个新项目,但是自动生成的代码显示了许多“无法解决”的错误,比如“Import Android.support.v7.app.ActionBaractivity;”代码中的“无法解决符号应用程序” 我的Android Studio版本是0.4.2,gradle版本是1.9 我的构建分级是:
我对JSF有一个非常奇怪的问题,但我不能自己解决它,因为没有错误消息我可以谷歌搜索。问题是,我有一个视图提交一个新的文章或更新一个现有的文章。 方法getArticle()返回-if?id=x是通过url设置的-id为x的文章POJO。否则,一个纯粹的空的新文章。根据设置的id,模式editArticle被设置为true或false。 我使用了BalusC的检查表(在JSF中没有调用action方
首先,我使用Windows 7 64位,WAMP 32位和火鸟32位。 我试图使用PHP与火鸟或interbase,所以我取消注释以下行从我的php.ini文件: 然后,当我启动WAMP时,会出现以下错误: 我已经尝试过的: 有人知道我该怎么解决这个问题吗?谢谢
我的数据库配置类: 和AppConfig: } 嗨,我上面有个错误,我不知道怎么修复,你能帮我吗?在添加这个bean之前,我的项目运行良好: }
我的线条怎样才能整齐又不太侧身?
我对Java中泛型的概念不熟悉。我有一个泛型方法,它的返回类型也是泛型。 我收到此错误,< code >无法解析T中的方法“getAa”。两个类都有这个成员变量,但是java并不理解,因为sub方法返回的是这个对象的一般列表。有没有办法改掉这个错误? 下面是我的代码,