2016-12-26 76 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 –