2016-12-26 75 views
1

我有一個心電圖圖形應用程序,圖形看起來像這樣。識別AndroidPlot中繪製點的網格

enter image description here

我需要知道的是,是否有可能知道在哪個點繪製的亞格說...格式如(ROW_INDEX,Column_Index中),或者是這樣的。其實我不知道這是否是一種可能的情況。所以,如果沒有辦法做到這一點,請讓我知道。 下面給出了我的圖形配置方法。

private void configureGraph() { 
/** 
    * ecgPlot corresponds to XYPlot 
    */ 
    XYGraphWidget graph = ecgPlot.getGraph(); 

    /** 
    * Paint to denote line color 
    */ 
    Paint paint = new Paint(); 
    paint.setColor(Color.WHITE); 
    paint.setStrokeWidth(3.0f); 
    /** 
    * Setting graph x and y boundary values 
    */ 
    ecgPlot.setRangeBoundaries(-40, 40, BoundaryMode.FIXED); 
    ecgPlot.setDomainBoundaries(0, 1500, BoundaryMode.FIXED); 

    ecgPlot.setPlotPadding(-10, 0, 0, 0); 

    /** 
    * Removes default bkg - ie; black 
    */ 
    ecgPlot.setBackgroundPaint(null); 
    graph.setBackgroundPaint(null); 
    graph.setGridBackgroundPaint(null); 
    /** 
    * Adjusting grid line width 
    */ 
    graph.getDomainGridLinePaint().setStrokeWidth(4.0f); 
    graph.getRangeGridLinePaint().setStrokeWidth(4.0f); 
    graph.getDomainSubGridLinePaint().setStrokeWidth(1.0f); 
    graph.getRangeSubGridLinePaint().setStrokeWidth(1.0f); 

    /** 
    * Removes border 
    */ 
    ecgPlot.setBorderPaint(null); 
    /** 
    * Setting grid color 
    */ 
    graph.getDomainGridLinePaint().setColor(getResources().getColor(R.color.colorECGGrid)); 
    graph.getRangeGridLinePaint().setColor(getResources().getColor(R.color.colorECGGrid)); 
    graph.getRangeSubGridLinePaint().setColor(getResources().getColor(R.color.colorECGGrid)); 
    graph.getDomainSubGridLinePaint().setColor(getResources().getColor(R.color.colorECGGrid)); 
    /** 
    * Setting number of sub grid lines per grid 
    */ 
    graph.setLinesPerDomainLabel(5); 
    graph.setLinesPerRangeLabel(5); 

    ecgPlot.setRangeStep(StepMode.INCREMENT_BY_VAL, 1); 
    ecgPlot.setDomainStepValue(75); 
    ecgPlot.setLinesPerDomainLabel(5); 
    ecgPlot.setDomainLabel(null); 
    ecgPlot.setRangeLabel(null); 

    Paint paintTest = new Paint(); 
    paintTest.setColor(Color.TRANSPARENT); 
    paintTest.setStrokeWidth(3.0f); 

    ecgLinePointFormatter.setLegendIconEnabled(false); 
    // PointLabelFormatter pointLabelFormatter = new PointLabelFormatter(); 
    // pointLabelFormatter.setTextPaint(paint); 

}                            

在此先感謝

+0

只是爲了確認,通過子網格你的意思是上述網格的5×5部分,是嗎? – Nick

+0

是的。準確地@Nick –

+0

你能展示你定義網格間距的代碼部分以及任何特殊的域/範圍邊界配置嗎? (你如何完成你的要求取決於這些變量) – Nick

回答

0

不幸的是我沒有在那裏我可以實際測試該代碼是否正確,但這裏是你如何可以從真實的XY值轉換爲亞格COORDS一個總體思路的地方:

double subX(Number x) { 
    // calculate the value each subgrid represents: 
    double stepVal = (plot.getBounds().getWidth().doubleValue()/75) * 5; 

    // find the value of x relative to the left edge of the screen 
    double xOff = x.doubleValue() - plot.getBounds().getMinX().doubleValue();  
    return xOff/stepVal; 
} 

double subY(Number y) { 
    double stepVal = plot.getBounds().getHeight().doubleValue()/5; 

    double yOff = y.doubleValue() - plot.getBounds().getMinY().doubleValue(); 
    return yOff/stepVal; 
} 

然後,給定數x和數y要轉化爲亞網格座標:

Number x = subX(realX); 
Number y = subY(realY); 

如果您需要像素值而不是實際值,則可以使用XYPlot.seriesToScreenX/Y(Number)XYPlot.screenToSeriesX/Y(Number)方法來回轉換。

+0

一旦我檢查它,我會回覆你@Nick –