yuxinburen / achartengine

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

Chart onClick fired by pan gesture when pan limits are hit. #318

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a BarChart with simple series
2. Set pan limits with setPanLimits.
3. Starting from a data series swipe left or right exceeding the set pan limit

What is the expected output? What do you see instead?
Given a swipe gesture, I expect chart then onClick not to fire.  However, chart 
onClick is fired. even though the touch release is way off its origination.

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

        int count = 12;
        String[] labels = new String[]{"Jan '13", "Feb '13", "Mar '13", "Apr '13", "May '13", "Jun '13", "Jul '13", "Aug '13", "Sep '13", "Oct '13", "Nov '13", "Dec '13"}; break
        int maxX = 240; 
        int bMargin = (int) (20 * density); 

        XYSeries visitsSeries = new XYSeries("Visits");
        for (int i = 0; i < count; i++)
        {
            int visitsCount = (int) (maxX * Math.random());
            visitsSeries.add(i, visitsCount);
        }

        XYSeriesRenderer visitsRenderer = new XYSeriesRenderer();
        visitsRenderer.setColor(Color.parseColor("#D6D6D6"));
        visitsRenderer.setChartValuesTextAlign(Align.CENTER);
        visitsRenderer.setChartValuesTextSize(density * 10);
        visitsRenderer.setLineWidth(2);
        visitsRenderer.setGradientEnabled(true);
        visitsRenderer.setGradientStart(0, Color.parseColor("#669900")); 
        visitsRenderer.setGradientStop(maxX, Color.parseColor("#99CC00")); 
        visitsRenderer.setDisplayChartValues(true);

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        dataset.addSeries(visitsSeries);

        XYMultipleSeriesRenderer chartRenderer = new XYMultipleSeriesRenderer();
        chartRenderer.setLabelsTextSize(10 * density);
        chartRenderer.setZoomEnabled(false,false);

        chartRenderer.setBarSpacing(.25);

        chartRenderer.setXLabelsAngle(45);
        chartRenderer.setXLabelsAlign(Align.LEFT);

        chartRenderer.setBackgroundColor(Color.TRANSPARENT); 
        chartRenderer.setMargins(new int[] {0, 0, bMargin, 0});
        chartRenderer.setYAxisMin(0);
        chartRenderer.setYAxisMax((maxX -1) * 1.1);
        chartRenderer.setXAxisMax(count);
        int minX = Math.max(-1, count - 10);
        chartRenderer.setXAxisMin(minX);
        chartRenderer.setApplyBackgroundColor(true);
        chartRenderer.setBackgroundColor(Color.TRANSPARENT);
        chartRenderer.setMarginsColor(getResources().getColor(R.color.transparent_background));     
        chartRenderer.setYLabels(0);
        chartRenderer.setXLabels(0);
        chartRenderer.setShowAxes(false);
        chartRenderer.setShowLegend(false);
        chartRenderer.setClickEnabled(true);        
        for (int i = 0; i < count; i++) chartRenderer.addXTextLabel(i, labels[i]);
        chartRenderer.addSeriesRenderer(visitsRenderer);

        chartRenderer.setPanEnabled(true, false);
        chartRenderer.setPanLimits(new double[]{0, count, 0, 0});

        _chart = (GraphicalView) ChartFactory.getBarChartView(getBaseContext(), dataset, chartRenderer, Type.DEFAULT);      
        _chart.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                SeriesSelection seriesSelection = _chart.getCurrentSeriesAndPoint();    

                if (seriesSelection != null)
                {
                    int xValue = (int) seriesSelection.getXValue();
                    int yValue = (int) seriesSelection.getValue();

                    // Displaying Toast Message
                    Toast.makeText(_context, String.format("x: %s, y: %s", xValue, yValue), Toast.LENGTH_SHORT).show();
                }
            }
        });

        _chartContainer.removeAllViews();
        _chartContainer.addView(_chart);

What version of the product binary library are you using?

Please provide any additional information below.

Original issue reported on code.google.com by r...@kennedycompound.org on 14 Jun 2013 at 1:22

GoogleCodeExporter commented 9 years ago
http://stackoverflow.com/questions/19447366/android-achartengine-panning-and-cli
ck-listener this will solve the problem

Original comment by oscar.G...@gmail.com on 12 Jan 2014 at 3:37