禁用缩放但在achartengine android中保持启用Pan

时间:2014-01-05 00:57:31

标签: android achartengine

我正在尝试禁用缩放缩放,但仍保持平移x为true,以便我可以在x轴上滚动以查看我的值

renderer.setPanEnabled(true,false); renderer.setZoomEnabled(false,false);

这不起作用。缩放似乎仍然有效,并且未被禁用。任何建议都将受到高度赞赏?

以下是代码段:

public class PerformanceGraph {

public View getView(Context context, List<SessionData> sessionDataList,int filterViewTotalShots) {

    int Y_MAX = (filterViewTotalShots*10);
    int Y_MIN = 0;
    int PADDING = (int)(Y_MAX*0.05);

    XYMultipleSeriesRenderer seriesRenderer = new XYMultipleSeriesRenderer();
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

    // Adding the Goal Series
    Integer goalScore = new GoalDatabase(context).GetGoalScore(filterViewTotalShots);
    XYSeries lineGoal = new XYSeries("Goal");
    lineGoal.add(0, goalScore);
    if(sessionDataList.size() == 0){
        lineGoal.add(0, goalScore);
    }
    else {
        lineGoal.add(sessionDataList.size()-1, goalScore);
    }

    dataset.addSeries(lineGoal);

    XYSeriesRenderer lineGoalRenderer = new XYSeriesRenderer();
    lineGoalRenderer.setChartValuesSpacing(1f);
    lineGoalRenderer.setColor(Color.rgb(140, 131, 131)); // #8c8383
    lineGoalRenderer.setLineWidth(2f);      
    seriesRenderer.addSeriesRenderer(lineGoalRenderer);     

    // Adding Score Series
    TimeSeries series = new TimeSeries("Scores");
    for(int i=0;i<sessionDataList.size();i++) {         
        SessionData data = sessionDataList.get(i);

        series.add(i, data.getTotalScore());
        series.addAnnotation(Utils.customFormattedDate(data.getDate()), i, Y_MIN - (2*PADDING) );

        // Creating line series to draw vertical lines
        XYSeries line = new XYSeries("Line");
        line.add(i, Y_MIN);
        line.add(i, Y_MAX);
        line.addAnnotation( data.getTotalScore() + "", i, Y_MAX + PADDING);

        dataset.addSeries(line);

        XYSeriesRenderer lineRenderer = new XYSeriesRenderer();
        lineRenderer.setChartValuesSpacing(1f);
        lineRenderer.setColor(Color.rgb(135, 38, 36)); // #7d2624
        lineRenderer.setLineWidth(2f);

        lineRenderer.setAnnotationsColor(Color.rgb(140, 131, 131)); // #8c8383
        lineRenderer.setAnnotationsTextSize(22f);

        seriesRenderer.addSeriesRenderer(lineRenderer);
    }
    dataset.addSeries(series);

    XYSeriesRenderer renderer = new XYSeriesRenderer();
    renderer.setPointStyle(PointStyle.CIRCLE);
    renderer.setFillPoints(true);
    renderer.setColor(Color.WHITE);
    renderer.setLineWidth(4f);

    renderer.setAnnotationsColor(Color.GRAY);
    renderer.setAnnotationsTextSize(22f);

    seriesRenderer.addSeriesRenderer(renderer);

    seriesRenderer.setShowAxes(false);
    seriesRenderer.setShowLegend(false);
    seriesRenderer.setShowLabels(false);
    seriesRenderer.setZoomButtonsVisible(false);
    seriesRenderer.setPanEnabled(true, false);
    seriesRenderer.setZoomEnabled(false, false);
    seriesRenderer.setMargins(new int[] {0, 0, 0, 0});

    seriesRenderer.setXAxisMin(-1);
    seriesRenderer.setXAxisMax(10);

    seriesRenderer.setYAxisMin(Y_MIN - (3*PADDING));
    seriesRenderer.setYAxisMax(Y_MAX + (3*PADDING));

    seriesRenderer.setPointSize(10f);

    seriesRenderer.setTextTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Lifestyle Rounded M54.ttf"));

    View view = ChartFactory.getLineChartView(context, dataset, seriesRenderer);

    return view;
}

}

1 个答案:

答案 0 :(得分:8)

意味着这个答案(正如你所评论的那样)。我在这里写这篇文章以便它可以帮助别人。

seriesRenderer.setPanEnabled(true, false);
seriesRenderer.setZoomEnabled(false, false);