hichamuradess / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

Problem with lineview flickering etc since android 4.1.1 #352

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create some random XY values in linechart
2. Using a 
3. Plot them in android 4.1.1
4. Using library 1.1.0

What is the expected output? What do you see instead?

in android 4.0 and below there are 4 lines shown correctly. Since android 4.1.1 
( samsung galaxy tab 2 7.0 and htc desire X) lines are flickering + switching 
colors + changing thickness. 

I'm not a expert in android => this is my first app, but it was working fine on 
older android versions.

Please provide a source code snippet that we can use to replicate the issue.

In mainprogram i call this : 

             XYChartBuilder Line = new XYChartBuilder();
             GraphicalView LineView = Line.getView(this, FirstCall,Xvals ,Yvals1,Yvals2,Yvals3,Yvals4);
             LinearLayout GraphLayout = (LinearLayout) findViewById(R.id.chart);
             GraphLayout.removeAllViews();
             GraphLayout.addView(LineView);

and the "method" is like this :

public class XYChartBuilder extends Activity {

    public boolean FirstcallLocal = false;
    public GraphicalView Backup;

    public GraphicalView getView(Context context, boolean Firstcall, final long[] Xval, float[] Yval,  float[] Yval2, float[] Yval3, float[] Yval4  )
    {
        MainActivity Main;
        Date[] datum = new Date[1000];
        final String[] dateString = new String[Xval.length];
        final SimpleDateFormat dateFormat = new SimpleDateFormat("H:mm");
        double XRange;
        int XSom, XNext;
        GraphicalView mChartview = null;
        double[] RS0 = new double[] {150.0, 295.0,-20.0,40.0};
        double[] RS1 = new double[] {150.0, 295.0,0.0,1000.0};
        double[] RS2 = new double[] {150.0, 295.0,0.0,MainActivity.Y2min};
        double[] Panlimits = new double[] {0.0,(double)Xval.length+3,-20.0,2000.0};

        final XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(3);

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

        XYSeries series = new XYSeries("Temp[°C]",0);
        for( int i = Yval.length-1 ; i >=0 ; i--)
        {
            //Random randomGenerator1 = new Random();
            //long randomlong = (long)randomGenerator1.nextInt(30);
            series.add((double)(Xval.length-1)-i,(double)Yval[i]);
            //Log.w("Resultseries1",String.valueOf(Yval[i])+" "+String.valueOf((double)Yval[i]));

        }
        XYSeries series2 = new XYSeries("Licht[J/(s.m²)]",1);
        for( int i = Yval2.length-1 ; i >=0 ; i--)
        {
            //Random randomGenerator2 = new Random();
             //long randomlong = (long)randomGenerator2.nextInt(1500);
            series2.add((double)(Xval.length-1)-i,(double)Yval2[i]);
            //Log.w("Resultseries1",String.valueOf(Yval2[i])+" "+String.valueOf((double)Yval2[i]));         
        }
        XYSeries series3 = new XYSeries("LichtSom[J/cm²]",2);
        for(int i = Yval3.length-1 ; i >=0 ; i--)
        {
            //Random randomGenerator3 = new Random();
            // long randomlong = (long)randomGenerator3.nextInt(200);
            series3.add((double)(Xval.length-1)-i,(double)Yval3[i]);
            //Log.w("Resultseries1",String.valueOf(Yval3[i])+" "+String.valueOf((double)Yval3[i]));

        }
        XYSeries series4 = new XYSeries("pomp",0);
        for( int i = Yval4.length-1 ; i >=0 ; i--)
        {
            //Random randomGenerator4 = new Random();
            //long randomlong = (long)randomGenerator4.nextInt(50);
            series4.add((double)(Xval.length-1)-i,(double)Yval4[i]);
            //Log.w("Resultseries1",String.valueOf(Yval4[i])+" "+String.valueOf((double)Yval4[i]));

        }

        dataset.addSeries(0,series);
        dataset.addSeries(1,series2);
        dataset.addSeries(2,series3);
        dataset.addSeries(0,series4);

        XYSeriesRenderer renderer = new XYSeriesRenderer();
        XYSeriesRenderer renderer2 = new XYSeriesRenderer();
        XYSeriesRenderer renderer3 = new XYSeriesRenderer();
        XYSeriesRenderer renderer4 = new XYSeriesRenderer();
        renderer.setColor(0xFF339900);
        renderer.setLineWidth(2.0f); 
        renderer2.setColor(0xFFFF9900);
        renderer2.setLineWidth(2.0f);
        renderer3.setColor(0xFFFFFF00);
        renderer3.setLineWidth(2.0f);
        renderer4.setColor(0xFF0066FF);
        renderer4.setLineWidth(2.0f);

        mRenderer.removeAllRenderers();
        mRenderer.setYLabelsAlign(Align.RIGHT, 0);
        mRenderer.setYLabelsAlign(Align.LEFT, 1);
        mRenderer.setYLabelsAlign(Align.RIGHT, 2);
        mRenderer.setYLabelsColor(0,0xFF339900);
        mRenderer.setYLabelsColor(1,0xFFFF9900);
        mRenderer.setYLabelsColor(2,0xFFFFFF00);
        mRenderer.setYAxisAlign(Align.LEFT, 0);
        mRenderer.setYAxisAlign(Align.RIGHT, 1);
        mRenderer.setYAxisAlign(Align.RIGHT, 2);
        mRenderer.setInitialRange(RS0, 0);
        mRenderer.setInitialRange(RS1, 1);
        mRenderer.setInitialRange(RS2, 2);
        mRenderer.setXAxisMin(MainActivity.X0min,0);
        mRenderer.setXAxisMin(MainActivity.X1min,1);
        mRenderer.setXAxisMin(MainActivity.X2min,2);
        mRenderer.setXAxisMax(MainActivity.X0max,0);
        mRenderer.setXAxisMax(MainActivity.X1max,1);
        mRenderer.setXAxisMax(MainActivity.X2max,2);
        mRenderer.setYAxisMin(MainActivity.Y0min,0);
        mRenderer.setYAxisMax(MainActivity.Y0max,0);
        mRenderer.setYAxisMin(MainActivity.Y1min,1);
        mRenderer.setYAxisMax(MainActivity.Y1max,1);
        mRenderer.setYAxisMin(MainActivity.Y2min,2);
        mRenderer.setPanLimits(Panlimits);
        mRenderer.addSeriesRenderer(0,renderer);
        mRenderer.addSeriesRenderer(1,renderer2);
        mRenderer.addSeriesRenderer(2,renderer3);
        mRenderer.addSeriesRenderer(0,renderer4);
        mRenderer.setShowGrid(true);
        mRenderer.setZoomButtonsVisible(true);
        mRenderer.setZoomEnabled(true,true);
        mRenderer.setPanEnabled(true, true);
        mRenderer.clearXTextLabels();
        mRenderer.setShowCustomTextGrid(true);
        mRenderer.setLegendTextSize(26);
        mRenderer.setLabelsTextSize(26);
        int[] Margins = {20,50,30,60};
        mRenderer.setMargins(Margins);

        XRange = MainActivity.X0max - MainActivity.X0min;
        //Log.w("Rangevangraph",String.valueOf(MainActivity.X0max)+" "+String.valueOf(MainActivity.X0min)+" "+String.valueOf(XRange));
        XSom = (int) (XRange / 6.0);
        XNext =  (int)MainActivity.X0min;
        int j = 0;
        for (int i =0 ; i <  Xval.length-1; i++) {
            //Random randomGenerator = new Random();

            if ( i == XNext )
            {
                dateString[i] =dateFormat.format(new Date(Xval[(Xval.length)-i]));
                //Log.w("Valuesvanaxis",dateString[i]+" "+String.valueOf(i));
                mRenderer.addXTextLabel(i, dateString[i]);
                j = j + 1;
                XNext = XNext + XSom;
            }

        }
        dateString[Xval.length-1] =dateFormat.format(new Date(Xval[(0)]));
        //Log.w("Valuesvanaxis",dateString[Xval.length-1]+" "+String.valueOf(Xval.length-1));
        mRenderer.addXTextLabel(Xval.length-1, dateString[Xval.length-1]);

        mRenderer.setYLabels(10);
        mRenderer.setXLabels(0);

        mChartview = ChartFactory.getLineChartView(context, dataset , mRenderer);

        mChartview.addZoomListener(new ZoomListener() {

            public void zoomApplied(ZoomEvent e) {

                  MainActivity.X0min =  mRenderer.getXAxisMin(0);
                  MainActivity.X0max =  mRenderer.getXAxisMax(0);
                  MainActivity.X1min = mRenderer.getXAxisMin(1);
                  MainActivity.X2min =  mRenderer.getXAxisMin(2);
                  MainActivity.Y0min =  mRenderer.getYAxisMin(0);
                  MainActivity.Y0max =  mRenderer.getYAxisMax(0);
                  MainActivity.Y1min = mRenderer.getYAxisMin(1);
                  MainActivity.Y1max =  mRenderer.getYAxisMax(1);
                  MainActivity.Y2min =  mRenderer.getYAxisMin(2);

                  MainActivity.X1max =  mRenderer.getXAxisMax(1);
                  MainActivity.X2max =  mRenderer.getXAxisMax(2);

              }

              public void zoomReset() {
                    double[] RS0 = new double[] {150.0, 295.0,-20.0,40.0};
                    double[] RS1 = new double[] {150.0, 295.0,0.0,1000.0};
                    double[] RS2 = new double[] {150.0, 295.0,0.0,2000.0};
                    mRenderer.setInitialRange(RS0, 0);
                    mRenderer.setInitialRange(RS1, 1);
                    mRenderer.setInitialRange(RS2, 2);

                    mRenderer.setXAxisMin(150.0,0);
                    mRenderer.setXAxisMin(150.0,1);
                    mRenderer.setXAxisMin(150.0,2);
                    mRenderer.setYAxisMin(-20.0,0);
                    mRenderer.setYAxisMax(40.0,0);
                    mRenderer.setYAxisMin(0.0,1);
                    mRenderer.setYAxisMax(1000.0,1);
                    mRenderer.setYAxisMin(0.0,2);

              }
            }, true, true);

        mChartview.addPanListener(new PanListener() {

                @Override
                public void panApplied() {

                      MainActivity.X0min =  mRenderer.getXAxisMin(0);
                      MainActivity.X0max =  mRenderer.getXAxisMax(0);
                      MainActivity.X1min = mRenderer.getXAxisMin(1);
                      MainActivity.X2min =  mRenderer.getXAxisMin(2);
                      MainActivity.Y0min =  mRenderer.getYAxisMin(0);
                      MainActivity.Y0max =  mRenderer.getYAxisMax(0);
                      MainActivity.Y1min = mRenderer.getYAxisMin(1);
                      MainActivity.Y1max =  mRenderer.getYAxisMax(1);
                      MainActivity.Y2min =  mRenderer.getYAxisMin(2);

                      MainActivity.X1max =  mRenderer.getXAxisMax(1);
                      MainActivity.X2max =  mRenderer.getXAxisMax(2);

                }
                }); 

        return mChartview;

    }

}

What version of the product binary library are you using?

1.1.0

Please provide any additional information below.

I'm not using intents, was not able to start it that way. I'm using a view in a 
linearlayout.

Thanks in advance

Original issue reported on code.google.com by mathias....@gmail.com on 15 Sep 2013 at 10:49

GoogleCodeExporter commented 9 years ago
seems to happen with scales 1 and 2, not to scale 0.

Original comment by mathias....@gmail.com on 26 Sep 2013 at 6:17