2012-05-26 7 views
5

¿Es posible crear un gráfico con valores fijos de xey? Mis valores de x son como 60, 90, 120, 180, 250, 375, 500, 750, 1000, pero el diagrama de Android crea 9 valores diferentes basados ​​en distancias iguales entre los valores.Gráfico de Android valores fijos en x ángulo

Number[] timestamps = {60, 90, 120, 180, 250, 375, 500, 750, 1000}; 

estoy usando mySimpleXYPlot.setDomainStep (XYStepMode.SUBDIVIDE, 9); y supongo que la solución está alrededor de este comando, pero no sé cómo hacerlo.

enter image description here

código completo:

mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); 
     Number[] numSightings = {70, 63, 56, 49, 43, 37, 32, 27, 23}; 

     Number[] timestamps = { 
      60, 90, 120, 180, 250, 375, 500, 750, 1000 

     }; 

     // create our series from our array of nums: 
     XYSeries series2 = new SimpleXYSeries(
       Arrays.asList(timestamps), 
       Arrays.asList(numSightings), 
       "USA"); 


     mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); 
     mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.BLACK); 
     mySimpleXYPlot.getGraphWidget().getGridLinePaint().setPathEffect(new DashPathEffect(new float[]{1,1}, 1)); 
     mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK); 
     mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK); 

     mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null); 
     mySimpleXYPlot.getBorderPaint().setStrokeWidth(1); 
     mySimpleXYPlot.getBorderPaint().setAntiAlias(false); 
     mySimpleXYPlot.getBorderPaint().setColor(Color.WHITE); 

     // Create a formatter to use for drawing a series using LineAndPointRenderer: 
     LineAndPointFormatter series1Format = new LineAndPointFormatter(
       Color.rgb(0, 100, 0),     // line color 
       Color.rgb(0, 100, 0),     // point color 
       Color.rgb(100, 200, 0));    // fill color 


     // setup our line fill paint to be a slightly transparent gradient: 
     Paint lineFill = new Paint(); 
     lineFill.setAlpha(200); 
     lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR)); 

     LineAndPointFormatter formatter = new LineAndPointFormatter(Color.rgb(0, 0,0), Color.BLUE, Color.RED); 
     formatter.setFillPaint(lineFill); 
     mySimpleXYPlot.getGraphWidget().setPaddingRight(2); 
     mySimpleXYPlot.addSeries(series2, formatter); 

     // draw a domain tick for each year: 
     mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, 9); 
     mySimpleXYPlot.setRangeBoundaries(-20,100, BoundaryMode.FIXED); 

     // customize our domain/range labels 
     mySimpleXYPlot.setDomainLabel("Frequency (Hz)"); 
     mySimpleXYPlot.setRangeLabel("Loud pressure (dB)"); 
     mySimpleXYPlot.getLegendWidget().setVisible(false); 

     // get rid of decimal points in our range labels: 
     mySimpleXYPlot.setRangeValueFormat(new DecimalFormat("0")); 

     //mySimpleXYPlot.setDomainValueFormat(new MyDateFormat()); 

     // by default, AndroidPlot displays developer guides to aid in laying out your plot. 
     // To get rid of them call disableAllMarkup(): 
     mySimpleXYPlot.disableAllMarkup(); 
+0

Cualquier éxito resolver esto? Tengo el mismo problema con las fechas en el eje del dominio. – blackwolf

Respuesta

5

XYStepType.INCREMENT_BY_VALUE

Este modo crea una marca para cada múltiplo de valor por encima y por debajo del origen. Vamos a modificar el ejemplo de inicio rápido de la siguiente manera:

mySimpleXYPlot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);

Esto le dice XYPlot para dibujar una garrapata para cada valor de dominio visible (x) cuando el módulo de x menos domainOrigin es cero, o para decirlo más simplemente , dibuje un tic en cada incremento de 1 comenzando desde domainOrigin. Ahora, nuestra parcela ahora se ve así:

enter image description here

De androidplot reference

Cuestiones relacionadas