我尝试为我的心电图创建一个自定义网格,但没有任何效果
我想得到一个具有特定突出显示行的网格。为了看到网格线,我使用xyMultipleSeriesRenderer.setXLabels(10)
和xyMultipleSeriesRenderer.setYLabels(10)
现在我想突出显示X和Y轴的每四条线,或者使它们比其他线条更大
这是我找到的东西。
这几乎就是我要找的东西。但我也需要y轴的threahold 有人有想法吗? 我对任何暗示感到高兴!
补充:
是的,突出显示线条非常容易。我只需在(0,20)处添加一个点,在(1000,20)处添加一个点。这对于水平线条非常好。
但如果我想对垂直线做同样的事情,我会得到一条对角线。对于静态折线图,它可以工作,如果我只添加到(30,0)处的一个点和(30,100)处的一个点。但是,如果我在实时线图中做同样的事情,我只能得到这个丑陋的倾斜。有人可以解释一下吗???? 我也尝试改变像(30,0)和(29,1000)这样的值,但我仍然得到对角线:(
答案 0 :(得分:1)
解决方案是添加一些额外的系列,每个系列只包含2个点,每个系列都会定义这样的一行。
答案 1 :(得分:0)
您好,谢谢您的回答。但我已经有两个系列。我有一个生成我的动态图表的sereies。我试着向你展示我的代码。
public class TraceActivity extends Activity implements Observer
{
private GraphicalView view;
private DynamicGraph dynamicGraph = new DynamicGraph();
private static Thread thread;
private dynamicValue value; //get from observable
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient);
/* Thread for the graphs */
thread = new Thread()
{
public void run()
{
for (int i = 0; i < 1000; i++)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
dynamicGraph.setRange();
Point point = getDataFromReceiver(i, value);
// here I try to add the vertical line
dynamicGraph.addNewLine(30, 0);
dynamicGraph.addNewLine(30, 100); // this line is painted at 31,100)
dynamicGraph.addNewPoint(point);
View.repaint();
}
}
};
thread.start();
}
public Point getDataFromReceiver(int x, int parameter)
{
return new Point(x, parameter);
}
@Override
protected void onStart()
{
super.onStart();
runOnUiThread(new ShowView(dynamicgraph.getView(this)));
}
private class ShowView implements Runnable
{
GraphicalView graphView;
public ShowTocoView(GraphicalView graphicalView)
{
graphView = graphicalView;
}
@Override
public void run()
{
if (View == null)
{
LinearLayout layout = (LinearLayout) findViewById(R.id.View);
View = graphView;
layout.addView(View);
}
else
{
View.repaint();
}
}
}
public class DynamicGraph
{
/** The chart view that displays the data. */
private GraphicalView view;
private TimeSeries Data = new TimeSeries("Toco");
private TimeSeries verticalLine = new TimeSeries("");
/** The main dataset that includes all the series that go into a chart. */
private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
/** The main renderer that includes all the renderers customizing a chart. */
private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
/** The most recently created renderer, customizing the current series. */
private XYSeriesRenderer rendererData = new XYSeriesRenderer();
private XYSeriesRenderer rendererVerticalLine = new XYSeriesRenderer();
GraphBuilder graphBuilder = new GraphBuilder(mRenderer, 10);
public TocoGraph()
{
mDataset.addSeries(Data);
mDataset.addSeries(verticalLine);
// graphBuilder build the grid and set the XYSeriesRenderer
graphBuilder.setAndAddXYSeriesRenderer(rendererData, Color.BLACK, 2f);
graphBuilder.setAndAddXYSeriesRenderer(rendererVerticalLine,
Color.rgb(247, 131, 62), 2f);
}
public GraphicalView getView(Context context)
{
view = ChartFactory.getLineChartView(context, mDataset, mRenderer);
return view;
}
public void setRange()
{
graphBuilder.setRange(Data, 100, 0);
}
public void addNewPoint(Point p)
{
Data.add(p.getX(), p.getY());
}
public void addNewLine(int x, int y)
{
verticalLine.add(x, y);
} }
所以我没有理由,为什么垂直线不垂直。你知道吗?