GraphView 双y轴

int[] ProbeType = { 0, 0, 0, 0, 0, 0,};
float[] chartX = { 0, 0, 0, 0, 0, 0,};
GraphView graph,graph2;
    private LineGraphSeries<DataPoint> mSeries0 = new LineGraphSeries<DataPoint>();
    private LineGraphSeries<DataPoint> mSeries1 = new LineGraphSeries<DataPoint>();
    private LineGraphSeries<DataPoint> mSeries2 = new LineGraphSeries<DataPoint>();
    private LineGraphSeries<DataPoint> mSeries3 = new LineGraphSeries<DataPoint>();
    private LineGraphSeries<DataPoint> mSeries4 = new LineGraphSeries<DataPoint>();
    private LineGraphSeries<DataPoint> mSeries5 = new LineGraphSeries<DataPoint>();
DisplayMetrics dm = getResources().getDisplayMetrics();

        graph = new GraphView(this);//获取图表画板
        graph.getViewport().setScalable(true);//设置缩放
        graph.getViewport().setScrollable(true);//设置滚动
        // set manual X bounds
        graph.getViewport().setXAxisBoundsManual(true);
        graph.getViewport().setMinX(0);
        graph.getViewport().setMaxX(10);//实验结束时一个界面显示出全部曲线。每隔1秒一个数据点,80个数据点需要80乘1=80秒

        // set manual Y bounds
        graph.getViewport().setYAxisBoundsManual(true);
        graph.getViewport().setMinY(0);//声波正弦曲线以y轴0值为基准线上下波动,大小为-127 到+128
        graph.getViewport().setMaxY(60);  //所有坐标轴的y值上下范围定为300 > 128
        graph.getViewport().setBackgroundColor(Color.LTGRAY);  
        //graph.getGridLabelRenderer().setHorizontalAxisTitle("时间");
        graph.getGridLabelRenderer().setVerticalAxisTitle("温度(℃)  压强(kPa)");
        graph.getGridLabelRenderer().setPadding(40);
        graph.getGridLabelRenderer().setVerticalLabelsColor(Color.BLUE);
        graph.getGridLabelRenderer().setHighlightZeroLines(false);//零线不高亮
        //graph.getGridLabelRenderer().setGridStyle(GridStyle.NONE);;//不显示格线
        graph.getGridLabelRenderer().setGridColor(Color.CYAN);
        //graph.setBackgroundResource(R.color.up_half_background_color);
        LayoutParams lPgraph = new LayoutParams(dm.widthPixels*2/3,LayoutParams.WRAP_CONTENT);
        lPgraph.setMargins(10, 0, 50, 0);
        graph.setLayoutParams(lPgraph);
        graph.setVisibility(View.VISIBLE);//VISIBLE:0 意思是可见的,INVISIBILITY:4 意思是不可见的,但还占着原来的空间,GONE:8 意思是不可见的,不占用原来的布局空间
        // legend 设置图例
        mSeries0.setTitle("温度");
        mSeries0.setColor(Color.BLUE);
        mSeries1.setTitle("压强");
        mSeries1.setColor(Color.RED);
        //把数据集放入画板
        graph.addSeries(mSeries0);
        graph.getLegendRenderer().setVisible(true);//图例可见
        graph.getLegendRenderer().setAlign(LegendAlign.TOP);//图例位置
        //graph.getGridLabelRenderer().setVerticalLabelsVisible(false);//隐藏y轴标签
        //graph.getGridLabelRenderer().setHorizontalLabelsVisible(false);//隐藏x轴标签

        // set second scale
        graph.getSecondScale().addSeries(mSeries1); //把数据集放入画板的第二刻度,相当于graph.addSeries(mSeries2); 不需要再graph.addSeries(mSeries2);
        // the y bounds are always manual for second scale
        graph.getSecondScale().setMinY(0);
        graph.getSecondScale().setMaxY(500);
        graph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(Color.RED);//第二坐标轴垂直标签颜色



        graph2 = new GraphView(this);//获取图表画板
        graph2.getViewport().setScalable(true);//设置缩放
        graph2.getViewport().setScrollable(true);//设置滚动
        // set manual X bounds
        graph2.getViewport().setXAxisBoundsManual(true);
        graph2.getViewport().setMinX(0);
        graph2.getViewport().setMaxX(10);//实验结束时一个界面显示出全部曲线。每隔1秒一个数据点,80个数据点需要80乘1=80秒

        // set manual Y bounds
        graph2.getViewport().setYAxisBoundsManual(true);
        graph2.getViewport().setMinY(0);//声波正弦曲线以y轴0值为基准线上下波动,大小为-127 到+128
        graph2.getViewport().setMaxY(50);  //所有坐标轴的y值上下范围定为300 > 128
        //graph2.getGridLabelRenderer().setHorizontalAxisTitle("时间");
        graph2.getGridLabelRenderer().setVerticalAxisTitle("氧气 、甲烷 、湿度 (%)    二氧化碳(ppm)");
        //graph2.getGridLabelRenderer().setLabelVerticalWidth(150); 
        //graph.getGridLabelRenderer().setVerticalLabelsAlign(Align.LEFT);  
        graph2.getGridLabelRenderer().setPadding(40);
        graph2.getGridLabelRenderer().setHighlightZeroLines(false);//零线不高亮
        //graph.getGridLabelRenderer().setGridStyle(GridStyle.NONE);;//不显示格线
        graph2.getGridLabelRenderer().setGridColor(Color.CYAN);
        //graph.setBackgroundResource(R.color.up_half_background_color);
        graph2.setLayoutParams(lPgraph);
        graph.setVisibility(View.VISIBLE);//VISIBLE:0 意思是可见的,INVISIBILITY:4 意思是不可见的,但还占着原来的空间,GONE:8 意思是不可见的,不占用原来的布局空间
        // legend 设置图例
        mSeries2.setTitle("氧气");
        mSeries2.setColor(Color.BLUE);
        mSeries3.setTitle("甲烷");
        mSeries3.setColor(Color.GREEN);
        mSeries4.setTitle("相对湿度");
        mSeries4.setColor(Color.YELLOW);
        mSeries5.setTitle("二氧化碳");
        mSeries5.setColor(Color.RED);

        //把数据集放入画板
        graph2.addSeries(mSeries2);
        graph2.addSeries(mSeries3);
        graph2.addSeries(mSeries4);
        graph2.getLegendRenderer().setVisible(true);//图例可见
        graph2.getLegendRenderer().setAlign(LegendAlign.TOP);//图例位置
        //graph.getGridLabelRenderer().setVerticalLabelsVisible(false);//隐藏y轴标签
        //graph.getGridLabelRenderer().setHorizontalLabelsVisible(false);//隐藏x轴标签

        // set second scale
        graph2.getSecondScale().addSeries(mSeries5);
        // the y bounds are always manual for second scale
        graph2.getSecondScale().setMinY(0);
        graph2.getSecondScale().setMaxY(500);
        graph2.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(Color.RED); //设置第二坐标尺垂直标签颜色
mSeries1.appendData(new DataPoint(chartX[index], fdat), true, 10);
chartX[index] += seq / 1000f;

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值