如何使用AchartEngine Android沿X轴移动Xaxis

时间:2013-12-30 09:05:58

标签: android achartengine

我正在使用AchartEngine api v1.1.0渲染条形图,如果我们可以移动屏幕底部的x轴在y轴上满足0,我需要帮助。

我已经发布了代码,以供参考我正在做的事情。

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    // Adding Income Series to the dataset
    dataset.addSeries(painLevelSeries);
    // Adding Expense Series to dataset
    dataset.addSeries(painLocationSeries);
    // Creating XYSeriesRenderer to customize painLevelSeries
    XYSeriesRenderer painLevelRenderer = new XYSeriesRenderer();
    painLevelRenderer.setColor(Color.rgb(220, 80, 80));
    painLevelRenderer.setFillPoints(true);
    painLevelRenderer.setLineWidth(5);
    painLevelRenderer.setDisplayChartValues(true);
    // Creating XYSeriesRenderer to customize painLocationSeries
    XYSeriesRenderer painLocationRenderer = new XYSeriesRenderer();
    painLocationRenderer.setColor(Color.parseColor("#003300"));
    painLocationRenderer.setFillPoints(true);
    painLocationRenderer.setLineWidth(5);
    painLocationRenderer.setDisplayChartValues(false);
    // Creating a XYMultipleSeriesRenderer to customize the whole chart
    XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
    multiRenderer.setChartTitleTextSize(20);
    multiRenderer.setLabelsTextSize(15);
    multiRenderer.setLegendTextSize(15);      
    multiRenderer.setXTitle("Pain Management");
    multiRenderer.setYTitle("Pain Level Effectiveness");
    multiRenderer.setXLabelsColor(Color.parseColor("#003300"));
    multiRenderer.setXLabels(0);
    multiRenderer.setYLabels(15);
    multiRenderer.setAxisTitleTextSize(30);
    multiRenderer.setYLabelsColor(expense, Color.parseColor("#FC1625"));
    multiRenderer.setMarginsColor(25);
    multiRenderer.setYLabelsPadding(15f);
    multiRenderer.setXLabelsPadding(15f);
    multiRenderer.setAxesColor(Color.parseColor("#003300"));
    multiRenderer.setLabelsColor(Color.parseColor("#003300"));
    multiRenderer.setMarginsColor(Color.parseColor("#FFFFFF"));
    multiRenderer.setZoomEnabled(false);
    multiRenderer.setInScroll(false);
    multiRenderer.setZoomEnabled(false, false);
    multiRenderer.setPanEnabled(false);
    multiRenderer.setMargins(new int[] { 10, 80, 15, 0 });
    multiRenderer.setBarSpacing(.1);
    multiRenderer.setXAxisMin(0.0);
    multiRenderer.setXAxisMax(10.0);
    multiRenderer.setYAxisMin(-10.0);
    multiRenderer.setYAxisMax(10.0);
    multiRenderer.addSeriesRenderer(painLevelRenderer);
    multiRenderer.addSeriesRenderer(painLocationRenderer);
    multiRenderer.setXLabelsAngle(-45);
    RelativeLayout chartContainer = 
     (RelativeLayout)      findViewById(R.id.painLocationContents);
    chartContainer.setBackgroundColor(Color.parseColor("#FFFFFF"));
    // Creating a Line Chart
    mChart = (GraphicalView)   
    ChartFactory.getBarChartView(getBaseContext(),dataset, multiRenderer, Type.DEFAULT);
    // Adding the Line Chart to the LinearLayout
    mChart.setBackgroundColor(Color.parseColor("#FFFFFF"));
    chartContainer.addView(mChart);!

快照:

enter image description here

感谢您的帮助。!!!

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式修改可见范围来移动轴:

renderer.setXAxisMin(minX);
renderer.setXAxisMax(maxX);

与Y轴相似。

完成上述操作后,请勿忘记致电:

chartView.repaint();