5

I am using achartengine for data that my application is continuously receiving over a socket connection. The point are plotted against time which is my x axis. Once the graph is in place a user can pan and zoom on the graph. Everything is buttery smooth. The only problem is that when the user zooms the graph, portions of the graph is also visible on the other side of x and y axis.

How do i restrict the graph from being visible outside the X and Y axis?

Here is a portion of my code.

XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();

renderer.setChartTitleTextSize(12);
renderer.setLabelsTextSize(15);
renderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01));
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.TRANSPARENT);
renderer.setZoomEnabled(true, true);
    renderer.setPointSize(5f);
renderer.setShowGrid(true);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setLabelsColor(getResources().getColor(R.color.black));
renderer.setXLabelsColor(getResources().getColor(R.color.black));
renderer.setYLabelsColor(0, getResources().getColor(R.color.black));
renderer.setDisplayValues(true);
renderer.setSelectableBuffer(20);
renderer.setShowLegend(false);

    renderer.setRange(new double[] { timeSeriesChart.getMinX(),
            timeSeriesChart.getMaxX(), 0/* minY */, maxY });

    renderer.setPanLimits(getChartLimit(
     isTimeChart, timeSeriesChart.getMinX(), timeSeriesChart.getMaxX(),
     (maxY*-1)+timeSeriesChart.getMinY(),
     maxY));

enter image description here

Umesh
  • 4,406
  • 2
  • 25
  • 37
  • What version of AChartEngine are you using? – Dan D. Sep 04 '13 at 10:48
  • I am using version 1.1.0 – Umesh Sep 04 '13 at 11:23
  • Did you download it from here: http://code.google.com/p/achartengine/downloads/list ? – Dan D. Sep 04 '13 at 17:19
  • Yes i did download it from there – Umesh Sep 05 '13 at 04:10
  • 3
    Hi Dan, I figured this out. The problem was in the line - renderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01)); changed it to renderer.setMarginsColor(Color.WHITE); and that did the trick.. somehow renderer.setMarginsColor(Color.TRANSPARENT) was not working. Luckily i had a white background so no problems for me.. – Umesh Sep 05 '13 at 09:10
  • 1
    Thanks @Umesh but my background is not white :-( – mcd Dec 27 '13 at 12:05
  • I have the same problem, but in my case (as mcd's) the background is not white (in fact it can contain graphics or a gradient) and thus Umesh's solution will not work. @Dan I know you are the original developer of ACE, any suggestions? – Ethan Holshouser Oct 03 '14 at 18:31

1 Answers1

0

I had a similar requirement. I solved it by clamping my dataset to a max and min value. Of course in my case it worked because I was transforming the data I received from a server before placing it in my dataset.

TimeSeries mTimeSeries;

...
...

private void addValue(Date time, double val){
    if(val >= MAX_VALUE){
        val = MAX_VALUE;
    }
    if(val <= MIN_VALUE){
        val = MIN_VALUE;
    }

    mTimeSeries.add(time, val);
}
curioustechizen
  • 10,572
  • 10
  • 61
  • 110