首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mpandroid图表某些方法无法解析

mpandroid图表某些方法无法解析
EN

Stack Overflow用户
提问于 2015-07-18 12:14:13
回答 1查看 796关注 0票数 1

因此,我使用了非常棒的MPAndroid图表库来创建一个简单的LineChart。我能够使用GitHub上的示例项目对其进行大量定制。

问题是,当我将它移到我自己的代码中时,某些方法不再能够被解决:

特别是mLineChart.setExtraOffsets()和mLineChart.setAutoScaleMinMaxEnabled()。可能还有其他的,但这是我唯一注意到的两个。

不过,其他的一切都很好。你知道为什么我不能访问这两个方法吗?我应该深入研究什么来更多地了解为什么会出现这种情况?

代码语言:javascript
复制
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中。不确定这是否是导致问题的原因。

EN

回答 1

Stack Overflow用户

发布于 2015-07-19 05:55:38

不要紧,我想通了。这是因为Maven和Gradle下载的库与网站上的示例项目中包含的库不完全相同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31487722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档