I'm using graphView library to draw a line graph in my android app. Since my x axes has more data, I want to make it horizontal scrollable, so that datas will not overlap with each other on smaller devices. So far I tried to add a HorizontalScrollView in my xml showed below, and it is able to make the whole graph scroll. My question is: if I want Y axes stay and only X axes scrollable, how to do that? Are there any GraphView api available?
My xml:
<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>
My java code:
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);
}
Thank you!