0

打电话的时候有问题setOnTouchListener。我也有检测错误的问题。我已经更改了该行的代码,但我仍然遇到同样的问题:

ChartView xv =(ChartView)findViewById(R.id.LinearLayout01);

我会得到示例中的坐标,但应用力会关闭。也许这是 achartengine 的问题,但我不确定。

    public class MainActivity extends Activity {

        private int pointx;
        private int pointy;

        //me declaro un string con los meses del año
        private String[] mYear = new String[] {
                    "2005", "2006" , "2007", "2008", "2009", "2010",
                    "2011", "2012" , "2013"
                };

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            XYSeries incomeSeries = new XYSeries("AÑOS");

            XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
            XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
            XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();




            ChartView xv =(ChartView)findViewById(R.id.LinearLayout01);
            xv.setOnTouchListener(new OnTouchListener(){
                public boolean onTouch(View v, MotionEvent event) {

                    pointx = (int)event.getX();
                    pointy = (int)event.getY();


                    Toast.makeText(MainActivity.this, "x="+Integer.toString(pointx)+"y="+Integer.toString(pointy), Toast.LENGTH_SHORT).show();
                    return false;
                }});

            int[] x = { 0,1,2,3 };
            int[] income = { 10,12,14,10};
            //XYSeries encapsula los valores de los gráficos XY como la línea, tiempo, superficie, dispersión 


            //añado dato a la categoria 1
            for(int i=0;i<x.length;i++)
            {
                incomeSeries.add(i,income[i]);//0 de 2000

                //float ancho = incomeRenderer.getLineWidth();

            }
            dataset.addSeries(incomeSeries);

            // creacion de un conjunto xa cada serie

            // Adding Income Series to the dataset

            // Creating XYSeriesRenderer to customize incomeSeries

            incomeRenderer.setColor(Color.WHITE);//rgb(130, 360, 230)130, 130, 230
            incomeRenderer.setFillPoints(true);//ESTABLECER relleno
            incomeRenderer.setLineWidth(1);//ancho = 2
            incomeRenderer.setDisplayChartValues(true);//establece valores de visualización de las gráficas

            // definir titulo y demas

            multiRenderer.setXLabels(0);//0
            multiRenderer.setChartTitle("AÑOS");
            multiRenderer.setXTitle("años ventas");
            multiRenderer.setYTitle("Cantidad en euros");
            multiRenderer.setZoomButtonsVisible(true); 
            multiRenderer.addSeriesRenderer(incomeRenderer);
            multiRenderer.setClickEnabled(true);

            multiRenderer.isClickEnabled();


            for(int i=0; i< x.length;i++){
                multiRenderer.addXTextLabel(i, mYear[i]);  


            }       

            // Creating an intent to plot bar chart using dataset and multipleRenderer      
            Intent intent = ChartFactory.getBarChartIntent(getBaseContext(), dataset, multiRenderer, Type.DEFAULT);

            // Start Activity
            startActivity(intent);

        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }

       /* public int[] getYTextLabelLocations() {
            return getYTextLabelLocations();
          }
        */

    }
4

0 回答 0