achartengine网格中突出显示的线条

时间:2013-06-20 11:28:43

标签: android grid achartengine

我尝试为我的心电图创建一个自定义网格,但没有任何效果 我想得到一个具有特定突出显示行的网格。为了看到网格线,我使用xyMultipleSeriesRenderer.setXLabels(10)xyMultipleSeriesRenderer.setYLabels(10) 现在我想突出显示X和Y轴的每四条线,或者使它们比其他线条更大 这是我找到的东西。

http://www.google.de/imgres?um=1&client=firefox-a&sa=N&rls=org.mozilla:de:official&hl=de&biw=1680&bih=920&tbm=isch&tbnid=0PCpcj6UTWULcM:&imgrefurl=http://android.codeandmagic.org/2012/10/achartengine-live-scrolling-graph/2012-10-03-19-16-10-2/&docid=yfaTOinxMsdA-M&imgurl=http://android.codeandmagic.org/wp-content/uploads/2012/10/2012-10-03-19.16.101.png&w=720&h=1280&ei=8bDCUdP3E8zPsgbKpICYBw&zoom=1&iact=rc&dur=317&page=1&tbnh=147&tbnw=83&start=0&ndsp=51&ved=1t:429,r:5,s:0,i:97&tx=29&ty=58

这几乎就是我要找的东西。但我也需要y轴的threahold 有人有想法吗? 我对任何暗示感到高兴!

补充:

是的,突出显示线条非常容易。我只需在(0,20)处添加一个点,在(1000,20)处添加一个点。这对于水平线条非常好。

但如果我想对垂直线做同样的事情,我会得到一条对角线。对于静态折线图,它可以工作,如果我只添加到(30,0)处的一个点和(30,100)处的一个点。但是,如果我在实时线图中做同样的事情,我只能得到这个丑陋的倾斜。有人可以解释一下吗???? 我也尝试改变像(30,0)和(29,1000)这样的值,但我仍然得到对角线:(

2 个答案:

答案 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);
}   }

所以我没有理由,为什么垂直线不垂直。你知道吗?