【发布时间】:2019-05-01 17:48:28
【问题描述】:
我被图表困住了。下面是已经绘制了两条线(红色和蓝色)的图表的屏幕截图。问题是蓝色的。我想使用第二个刻度(即右侧的 Y 轴)和 X 轴来绘制这条线,目前它使用左侧的 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);
}
}
【问题讨论】:
-
您需要分享您的代码,以便我们知道您做错了什么
标签: android