I am stuck with a graph. Below is screenshot of a graph where two lines are already drawn (red and blue). Problem is with blue one. I want to use second scale (which is the Y axis on right hand side) along with X axis to plot this line which is not happening at the moment it is using Y-axis which is on left hand side to plot just like the red line.

I am using GRAPHVIEW Library in android.

enter image description here

 private void setBothSidedGraph() {
    //this is used to remove the default thickness on both axis
    graph.getGridLabelRenderer().setHighlightZeroLines(false);

    // this is used to remove the vertical lines from graph
    graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.HORIZONTAL);

    // this will draw a border aroung graph and will also show both axis
    graph.getViewport().setDrawBorder(true);

    //setting the title for both the axis
    GridLabelRenderer gridLabel = graph.getGridLabelRenderer();
    // gridLabel.setHorizontalAxisTitle("Singles");
    // gridLabel.setVerticalAxisTitle("Volume (bbl)");


    // manunal bounds for left-Yaxis and setting manual bound will break it accordingly evenly

    graph.getViewport().setMinY(0);
    graph.getViewport().setMaxY(1600);
    graph.getViewport().setYAxisBoundsManual(true);


    arrDepth.add(0);
    arrDepth.add(1);
    arrDepth.add(2);
    arrDepth.add(3);
    arrDepth.add(4);
    arrDepth.add(5);


    arrSingles.add(650);
    arrSingles.add(650);
    arrSingles.add(650);
    arrSingles.add(650);
    arrSingles.add(650);
    arrSingles.add(650);






  /*  // *****Data for the lines to be drawn****//*/
    LineGraphSeries<DataPoint> line1 = new LineGraphSeries<>(new DataPoint[] {

            new DataPoint(0, 650),
            new DataPoint(1, 550),
            new DataPoint(2, 660),
            new DataPoint(3, 575),
            new DataPoint(4, 650)
    });
    */

    //adding DataPoints on Line to be shown
    for (int i = 0; i < arrTimeForGraph.size(); i++) {
        line1.appendData((new DataPoint(arrTimeForGraph.get(i), arrCirculatingPressureForGraph.get(i))), true, arrTimeForGraph.get(arrTimeForGraph.size() - 1).intValue());
        line2.appendData((new DataPoint(arrTimeForGraph.get(i), 150)), true, arrTimeForGraph.get(arrTimeForGraph.size() - 1).intValue(),false);

    }



    line1.setThickness(3);//Color of Line to be Drawn
    line1.setDataPointsRadius(7);
    line1.setDrawDataPoints(true);  //Lines to be drawn should hold points in it
    line1.setColor(Color.RED);      //Color of Line to be Drawn




    line2.setThickness(3);//Color of Line to be Drawn
    line2.setDataPointsRadius(7);
    line2.setDrawDataPoints(true);  //Lines to be drawn should hold points in it
    line2.setColor(Color.BLUE);      //Color of Line to be Drawn


    canvas = new Canvas();



    line2.draw(graph,canvas,true);


    //Lines added to graph to be graph
    graph.addSeries(line1);
    graph.addSeries(line2);

    graph.isLayoutDirectionResolved();
    // setting bounds for Right Yaxis and setNumverticalLabels(9) will break it in 9 parts.
    graph.getSecondScale().setMinY(0);
    graph.getSecondScale().setMaxY(240);
    graph.getGridLabelRenderer().setNumVerticalLabels(9);

    // graph.getGridLabelRenderer().setVerticalLabelsColor(Color.TRANSPARENT);

    // graph.setContentDescription("Trip Sheet Volume Vs. Depth");
    graph.getGridLabelRenderer().setPadding(50);
    graph.getGridLabelRenderer().setVerticalLabelsColor(Color.RED);
     graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.TRANSPARENT);

    graph.getViewport().setXAxisBoundsManual(true);
    graph.getViewport().setMinX(0);
    graph.getViewport().setMaxX(arrTimeForGraph.get(10));


    if (isTablet720) {
        gridLabel.setVerticalAxisTitleTextSize(40f);
        gridLabel.setHorizontalAxisTitleTextSize(40f);

        graph.setTitleTextSize(40);

    } else {
        gridLabel.setVerticalAxisTitleTextSize(30f);
        gridLabel.setHorizontalAxisTitleTextSize(30f);

        graph.setTitleTextSize(30);
    }


}

1 Answers

0
Leo On Best Solutions

I believe that when you do the following...

    graph.addSeries(line1);
    graph.addSeries(line2);

Those series are added to the first scale. If you want to add the second series (line2) to the second scale, then you should do the following...

    graph.addSeries(line1);
    graph.getSecondScale().addSeries(line2);