Android GraphView仅使x轴水平滚动
我正在使用graphView库在我的android应用程序中绘制线图。因为我的x轴有更多的数据,所以我想让它水平滚动,这样数据就不会在较小的设备上相互重叠。到目前为止,我尝试在下面显示的xml中添加一个HorizontalScrollView,它能够使整个图形滚动。 我的问题是:如果我希望Y轴保持不变,并且只有X轴可以滚动,如何做到这一点?是否有GraphView api可用 我的xml:Android GraphView仅使x轴水平滚动,android,scroll,android-graphview,Android,Scroll,Android Graphview,我正在使用graphView库在我的android应用程序中绘制线图。因为我的x轴有更多的数据,所以我想让它水平滚动,这样数据就不会在较小的设备上相互重叠。到目前为止,我尝试在下面显示的xml中添加一个HorizontalScrollView,它能够使整个图形滚动。 我的问题是:如果我希望Y轴保持不变,并且只有X轴可以滚动,如何做到这一点?是否有GraphView api可用 我的xml: <HorizontalScrollView android:id="@+id/horiz
<HorizontalScrollView android:id="@+id/horizontalScroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:fadingEdgeLength="20dp">
<LinearLayout
android:id="@+id/graph_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CustomFontTextView
style=""
android:layout_marginTop=""
android:layout_marginBottom=""
android:focusable="true"
android:text="graph_header" />
<LinearLayout
android:id="@+id/Graph"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="190dip"
android:contentDescription="@string/talkback_graph"
android:orientation="vertical" />
</LinearLayout>
</HorizontalScrollView>
我的java代码:
public void setGraphView(Map<Integer, Integer> dt,String[] horizontalLabels ){
GraphViewData[] graphData = new GraphViewData[dt.size()];
int graphPos=0;
for(int pos:dt.keySet())
{
graphData[graphPos++] = new GraphViewData(pos, dt.get(pos));
}
GraphViewSeries series = new GraphViewSeries(graphData);
LineGraphView lineGraphView = new LineGraphView( getMainActivity(), "" );
lineGraphView.setScrollable(true);
lineGraphView.setScalable(false);
lineGraphView.setPadding(10, 10, 10, 10);
lineGraphView.setHorizontalScrollBarEnabled(true);
lineGraphView.setGravity(Gravity.CENTER);
lineGraphView.setManualYAxisBounds(500, 300);
lineGraphView.setDrawDataPoints(true);
lineGraphView.setDataPointsRadius(14f);
lineGraphView.getGraphViewStyle().setGridColor(Color.RED);
lineGraphView.setHorizontalLabels(horizontalLabels);
lineGraphView.setVerticalLabels(new String[]{"max 500", "min 300"});
lineGraphView.getGraphViewStyle().setTextSize(getResources().getDimension(R.dimen.cell_text_size));
lineGraphView.getGraphViewStyle().setVerticalLabelsWidth(70);
lineGraphView.getGraphViewStyle().setVerticalLabelsAlign(Align.LEFT);
lineGraphView.addSeries(series);
graphView.addView(lineGraphView);
}
public void setGraphView(映射dt,字符串[]水平标签){
GraphViewData[]graphData=新的GraphViewData[dt.size()];
int-graphPos=0;
对于(int pos:dt.keySet())
{
graphData[graphPos++]=新的GraphViewData(pos,dt.get(pos));
}
GraphViewSeries=新的GraphViewSeries(graphData);
LineGraphView LineGraphView=新建LineGraphView(getMainActivity(),“”);
线形图视图设置可滚动(真);
lineGraphView.setScalable(假);
线条图视图设置填充(10,10,10,10);
lineGraphView.setHorizontalScrollBarEnabled(true);
线图视图设置重力(重心);
线图视图设置手册轴向边界(500300);
lineGraphView.setDrawDataPoints(真);
线形图视图设置数据点半径(14f);
lineGraphView.getGraphViewStyle().setGridColor(Color.RED);
线形图视图设置水平标签(水平标签);
lineGraphView.setVerticalLabels(新字符串[]{“max 500”,“min 300”});
lineGraphView.getGraphViewStyle().setTextSize(getResources().getDimension(R.dimen.cell_text_size));
lineGraphView.getGraphViewStyle().setVerticalLabelsWidth(70);
lineGraphView.getGraphViewStyle().setVerticalLabelsAlign(Align.LEFT);
lineGraphView.addSeries(系列);
graphView.addView(lineGraphView);
}
谢谢大家! lineGraphView.setScrollableY(真); 线形图视图设置刻度(假) 对于Y轴,它应该使用不同的api