我陷入了困境。以下是已绘制两条线(红色和蓝色)的图形的屏幕截图。问题是蓝色的。我想与X轴一起使用第二个比例尺(右侧的Y轴)来绘制这条线,而这是它在左侧使用Y轴进行绘制的那一刻,就像红色一样线。
我正在android中使用GRAPHVIEW库。
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);
}
}
答案 0 :(得分:0)
我相信当您执行以下操作时...
graph.addSeries(line1);
graph.addSeries(line2);
那些系列被添加到第一等级。如果要将第二个系列(line2
)添加到第二个比例尺,则应执行以下操作...
graph.addSeries(line1);
graph.getSecondScale().addSeries(line2);