日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 芯聞號 > 充電吧
[導讀]最近做室內定位需要繪出加速度傳感器輸出的三個方向的加速度曲線,找到了開源https://github.com/jjoe64/GraphView-Demos,省去了要重新學MatLab *=*。在htt

最近做室內定位需要繪出加速度傳感器輸出的三個方向的加速度曲線,找到了開源https://github.com/jjoe64/GraphView-Demos,省去了要重新學MatLab *=*。

在http://www.android-graphview.org/download--getting-started.html下載.jar包。

1、GraphView的使用和普通View的使用相同。

2、支持三種圖表:Line和Bar、Point。


GraphView?graph?=?(GraphView)?findViewById(R.id.graph);
		LineGraphSeriesseries?=?new?LineGraphSeries(new?DataPoint[]?{
				?new?DataPoint(0,?1),
	????			new?DataPoint(1,?5),
	????			new?DataPoint(2,?3),
	????			new?DataPoint(3,?2),
	????			new?DataPoint(4,?6)
		});graph.addSeries(series);


?GraphView?graph?=?(GraphView)?rootView.findViewById(R.id.graph);
????????BarGraphSeriesseries?=?new?BarGraphSeries(new?DataPoint[]?{
????????????????new?DataPoint(0,?-2),
????????????????new?DataPoint(1,?5),
????????????????new?DataPoint(2,?3),
????????????????new?DataPoint(3,?2),
????????????????new?DataPoint(4,?6)
????????});
????????series.setSpacing(30);
????????graph.addSeries(series);


PointsGraphSeriesseries3?=?new?PointsGraphSeries(new?DataPoint[]?{
			????new?DataPoint(0,?0),
			????new?DataPoint(1,?3),
			????new?DataPoint(2,?1),
			????new?DataPoint(3,?0),
			????new?DataPoint(4,?4)
			});
			graph.addSeries(series3);
			series3.setShape(PointsGraphSeries.Shape.TRIANGLE);//設置點的形狀
			series3.setColor(Color.YELLOW);


也可以在XML中使用,但通過.jar包的不支持此功能。


 


3、設置各種屬性

設置每條曲線的標注:


graph.getLegendRenderer().setVisible(true);
		graph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP);//右上角對每條線注釋
		graph.getLegendRenderer().setTextColor(Color.WHITE);//標注字的顏色
		series.setTitle("foo");
		series1.setTitle("bar");


設置軸的數據顯示格式:


//設置軸分割數字格式
		NumberFormat?nf?=?NumberFormat.getInstance();
		nf.setMinimumFractionDigits(1);//小數位數
		nf.setMinimumIntegerDigits(2);//整數部分位數
		graph.getGridLabelRenderer().setLabelFormatter(new?DefaultLabelFormatter(nf,?nf));


自定義畫筆:


//自定義畫筆
		Paint?paint?=?new?Paint();
		paint.setStyle(Paint.Style.STROKE);
		paint.setStrokeWidth(10);
		paint.setPathEffect(new?DashPathEffect(new?float[]{8,?5},?0));
		series1.setCustomPaint(paint);


點擊事件:


//線條點擊事件
		series.setOnDataPointTapListener(new?OnDataPointTapListener()?{
		????@Override
		????public?void?onTap(Series?series,?DataPointInterface?dataPoint)?{
		????????Toast.makeText(MainActivity.this,?"Series1:?On?Data?Point?clicked:?"+dataPoint,?Toast.LENGTH_SHORT).show();
		????}
		});		


設置表格(分割線)顏色:


graph.getGridLabelRenderer().setGridColor(Color.WHITE);//表格顏色


實例展示:

自定義軸標簽:


graph.getGridLabelRenderer().setLabelFormatter(new?DefaultLabelFormatter()?{
????????????@Override
????????????public?String?formatLabel(double?value,?boolean?isValueX)?{
????????????????if?(isValueX)?{
????????????????????//?show?normal?x?values
????????????????????return?super.formatLabel(value,?isValueX);
????????????????}?else?{
????????????????????//?show?currency?for?y?values
????????????????????return?super.formatLabel(value,?isValueX)?+?"*";
????????????????}
????????????}
????????});




X軸設置為時間:


????????//?generate?Dates
????????Calendar?calendar?=?Calendar.getInstance();
????????Date?d1?=?calendar.getTime();
????????calendar.add(Calendar.DATE,?1);
????????Date?d2?=?calendar.getTime();
????????calendar.add(Calendar.DATE,?1);
????????Date?d3?=?calendar.getTime();

????????GraphView?graph?=?(GraphView)?rootView.findViewById(R.id.graph);

????????//?you?can?directly?pass?Date?objects?to?DataPoint-Constructor
????????//?this?will?convert?the?Date?to?double?via?Date#getTime()
????????LineGraphSeriesseries?=?new?LineGraphSeries(new?DataPoint[]?{
????????????????new?DataPoint(d1,?1),
????????????????new?DataPoint(d2,?5),
????????????????new?DataPoint(d3,?3)
????????});
????????graph.addSeries(series);

????????//?set?date?label?formatter
????????graph.getGridLabelRenderer().setLabelFormatter(new?DateAsXAxisLabelFormatter(getActivity()));
????????graph.getGridLabelRenderer().setNumHorizontalLabels(3);?//?only?4?because?of?the?space

????????//?set?manual?x?bounds?to?have?nice?steps
????????graph.getViewport().setMinX(d1.getTime());
????????graph.getViewport().setMaxX(d3.getTime());
????????graph.getViewport().setXAxisBoundsManual(true);

????????//?as?we?use?dates?as?labels,?the?human?rounding?to?nice?readable?numbers
????????//?is?not?nessecary
????????graph.getGridLabelRenderer().setHumanRounding(false);



設置X、Y軸 Bounds:


?//?set?manual?X?bounds
????????graph.getViewport().setXAxisBoundsManual(true);
????????graph.getViewport().setMinX(0.5);
????????graph.getViewport().setMaxX(3.5);

????????//?set?manual?Y?bounds
????????graph.getViewport().setYAxisBoundsManual(true);
????????graph.getViewport().setMinY(3.5);
????????graph.getViewport().setMaxY(8);



設置圖表可以縮放:


//?enable?scaling
????????graph.getViewport().setScalable(true);


設置Y軸可以Auto,圖表可以橫向滑動:


//?enable?scrolling
????????graph.getViewport().setScrollable(true);

這只左右兩個Y軸:


//?set?second?scale
????????graph.getSecondScale().addSeries(series2);
????????//?the?y?bounds?are?always?manual?for?second?scale
????????graph.getSecondScale().setMinY(0);
????????graph.getSecondScale().setMaxY(100);
????????series2.setColor(Color.RED);
????????graph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(Color.RED);

????????//?legend
????????series.setTitle("foo");
????????series2.setTitle("bar");
????????graph.getLegendRenderer().setVisible(true);
????????graph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP);

????????graph.getViewport().setBackgroundColor(Color.GRAY);




使用 staticLables:


?//?use?static?labels?for?horizontal?and?vertical?labels
????????StaticLabelsFormatter?staticLabelsFormatter?=?new?StaticLabelsFormatter(graph);
????????staticLabelsFormatter.setHorizontalLabels(new?String[]?{"old",?"middle",?"new"});
????????staticLabelsFormatter.setVerticalLabels(new?String[]?{"low",?"middle",?"high"});
????????graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);



設置軸Lables:


?//?titles
????????graph.setTitle("Chart?Title");
????????graph.getGridLabelRenderer().setVerticalAxisTitle("Vertical?Axis");
????????graph.getGridLabelRenderer().setHorizontalAxisTitle("Horizontal?Axis");

標簽、背景色、字體、字大小、顏色....Styling:


?//?styling?grid/labels
????????graph.getGridLabelRenderer().setGridColor(Color.RED);
????????graph.getGridLabelRenderer().setHighlightZeroLines(false);
????????graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.GREEN);//水平軸字體顏色
????????graph.getGridLabelRenderer().setVerticalLabelsColor(Color.RED);//垂直軸字顏色
????????graph.getGridLabelRenderer().setVerticalLabelsAlign(Paint.Align.LEFT);
????????graph.getGridLabelRenderer().setLabelVerticalWidth(150);
????????graph.getGridLabelRenderer().setTextSize(40);//字大小
????????graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.HORIZONTAL);//表格樣式,水平線
????????graph.getGridLabelRenderer().reloadStyles();
????????graph.getGridLabelRenderer().setHorizontalLabelsAngle(120);//水平軸標簽傾斜角


????????//?styling?viewport
????????graph.getViewport().setBackgroundColor(Color.argb(255,?222,?222,?222));//圖表背景色
????????graph.getViewport().setDrawBorder(true);
????????graph.getViewport().setBorderColor(Color.BLUE);

????????//?styling?series
????????series.setTitle("Random?Curve?1");
????????series.setColor(Color.GREEN);
????????series.setDrawDataPoints(true);
????????series.setDataPointsRadius(10);
????????series.setThickness(8);

????????series2.setTitle("Random?Curve?2");
????????series2.setDrawBackground(true);
????????series2.setBackgroundColor(Color.argb(100,?255,?255,?0));
????????Paint?paint?=?new?Paint();
????????paint.setStyle(Paint.Style.STROKE);
????????paint.setStrokeWidth(10);
????????paint.setPathEffect(new?DashPathEffect(new?float[]{8,?5},?0));
????????series2.setCustomPaint(paint);

????????//?styling?legend?注釋每條線代表什么
????????graph.getLegendRenderer().setVisible(true);
????????graph.getLegendRenderer().setTextSize(25);
????????graph.getLegendRenderer().setBackgroundColor(Color.argb(150,?50,?0,?0));
????????graph.getLegendRenderer().setTextColor(Color.WHITE);
????????//graph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP);
????????//graph.getLegendRenderer().setMargin(30);
????????graph.getLegendRenderer().setFixedPosition(150,?0);


本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉