SQLite数据库浏览器中的小数

时间:2011-10-06 08:36:17

标签: java android sqlite

sqlite是否接受小数点? 我可以从sqlite数据库中检索小数点数据并显示在图表中吗?

例如:我将日期存储为“6.10”(10月6日) 然而,当我检索它时,它只显示6。 所以,我可能知道我的代码是否在某处出错了?

public class Graph extends Activity implements OnTouchListener
{

private XYPlot mySimpleXYPlot;
private SimpleXYSeries mySeries;
private PointF minXY;
private PointF maxXY;
private double minDif;
private TextView txtView;
final private double difPadding = 0.1;
private float absMinX;
private float absMaxX;
private float minNoError;
private float maxNoError;

@Override
public void onCreate(Bundle savedInstanceState)
{

    super.onCreate(savedInstanceState);
    setContentView(R.layout.graph);

    mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
    mySimpleXYPlot.setOnTouchListener(this);

    databaseHelper baseHelper = new databaseHelper(this); 

    try {

        baseHelper.createDataBase();
        baseHelper.openDataBase();

} catch (IOException ioe) {
                    ioe.printStackTrace();

}

   Cursor a = baseHelper.getData();

   Number[] yArray = new Number[a.getCount()];
   Number[] xArray = new Number[a.getCount()];

   if(a.moveToFirst()){

          yArray[0]=a.getInt(2);
          xArray[0]=a.getInt(1);

           }
   for (int i=1; i<a.getCount(); i++) {
       if(a.moveToNext()) { 
           yArray[i] = a.getInt(2); 
           xArray[i] = a.getInt(1);
       }
   }


    mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

try {
    baseHelper.openDataBase();
}catch(SQLException sqle){
    System.out.println(sqle);
    throw sqle;

}

try {
    baseHelper.openDataBase();
    baseHelper.fetchAllXYDATA();
}catch(SQLException sqle1){
    throw sqle1;

}
   //create our series from our array of numbers: 
   mySeries = new SimpleXYSeries(Arrays.asList(xArray),Arrays.asList(yArray), "Water Spilled");

       Widget domainLabelWidget = mySimpleXYPlot.getDomainLabelWidget();

       mySimpleXYPlot.position(domainLabelWidget,                     // the widget to position
                               45,                                    // x position value, in this case 45 pixels (375)
                               XLayoutStyle.ABSOLUTE_FROM_LEFT,       // how the x position value is applied, in this case from the left
                               -5,                                     // y position value, 0
                               YLayoutStyle.ABSOLUTE_FROM_BOTTOM,     // how the y position is applied, in this case from the bottom
                               AnchorPosition.LEFT_BOTTOM);

       // AREA INSIDE THE XY AXIS
       mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.TRANSPARENT);
       mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.TRANSPARENT);

       mySimpleXYPlot.getGraphWidget().getGridLinePaint().setPathEffect(new DashPathEffect(new float[] {1,0},1));

       // X-AXIS
       mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.WHITE);

       //Numbers 
       //mySimpleXYPlot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLUE);

       // Y-AXIS
       mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.WHITE);

       mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.NONE, null, null);
       mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setColor(Color.TRANSPARENT);
       mySimpleXYPlot.getBorderPaint().setStrokeWidth(5);
       mySimpleXYPlot.getBorderPaint().setAntiAlias(false);

       //EXTERIOR BORDER
       mySimpleXYPlot.getBorderPaint().setColor(Color.TRANSPARENT);


       // 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.TRANSPARENT, Color.TRANSPARENT, Shader.TileMode.MIRROR));

       LineAndPointFormatter formatter  = new LineAndPointFormatter(Color.rgb(0, 255, 0), Color.GREEN, Color.GREEN);
       formatter.setFillPaint(lineFill);
       mySimpleXYPlot.getGraphWidget().setPaddingRight(15);
       mySimpleXYPlot.addSeries(mySeries, formatter);

       // draw a domain tick for each year:
      mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, xArray.length);
      mySimpleXYPlot.setRangeStep(XYStepMode.SUBDIVIDE, yArray.length);

       // customize our domain/range labels
       mySimpleXYPlot.setDomainLabel("Date (DD)");
       mySimpleXYPlot.setRangeLabel("Water Spill (ml)");

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

       mySimpleXYPlot.setDomainValueFormat(new DecimalFormat("0"));

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

       mySimpleXYPlot.getScrollX();

       mySimpleXYPlot.redraw();
}

1 个答案:

答案 0 :(得分:0)

getInt显然会返回一个Int。

你需要调用getDouble来获取小数值。

此外,您需要将REAL sqlite类型用于Decimal值。