android - 如何使用图形视图的第二个比例在android中进行绘图
问题描述
我被一张图表困住了。下面是已经绘制了两条线(红色和蓝色)的图表的屏幕截图。问题是蓝色的。我想使用第二个刻度(即右侧的 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);
}
}
解决方案
我相信当您执行以下操作时...
graph.addSeries(line1);
graph.addSeries(line2);
这些系列被添加到第一级。如果您想将第二个系列 ( line2
) 添加到第二个刻度,那么您应该执行以下操作...
graph.addSeries(line1);
graph.getSecondScale().addSeries(line2);
推荐阅读
- python - 如何跟踪可执行文件并执行 bash 命令?
- python - 从 JSON 中的地图对象读取数据到 Pandas Dataframe
- activecollab - 如何查看 ActiveCollab v2.3.2 上的活动
- flyway - Flyway迁移错误地改变了
- octave - 在八度音程中运行时,我在所有程序中都遇到了类似的错误
- xslt - 如何在 XQuery 中检索“外部标签”属性选择?
- php - 如何通过在具有“A”id 的“B”数组中搜索来返回“C”值
- flutter - 在 Liquidswipe 中使用 Offlinebuilder 时出现错误
- windows - postgres:强制本地连接使用没有 pg_hba.conf 的密码
- javascript - 为什么我不能将 borderRadius 应用到这个 React 引导选项卡?