目錄
第8節(jié).Setting Colors(MPAndroidChart中文翻譯)
第9節(jié).Formatting Data Values (ValueFormatter)(MPAndroidChart中文翻譯)
第10節(jié)-Formatting Axis Values (AxisValueFormatter)(MPAndroidChart中文翻譯)
第11節(jié).General Settings & Styling(MPAndroidChart中文翻譯)
第12節(jié).Specific Settings & Styling(MPAndroidChart中文翻譯)
第13節(jié).Legend(MPAndroidChart中文翻譯)
第14節(jié).Dynamic & Realtime Data(MPAndroidChart中文翻譯)
第15節(jié). Modifying the Viewport(MPAndroidChart中文翻譯)
第16節(jié).Animations(MPAndroidChart中文翻譯)
第17節(jié). MarkerView (Popup View)(MPAndroidChart中文翻譯)
第18節(jié). The ChartData class(MPAndroidChart中文翻譯)
第19節(jié). ChartData subclasses(MPAndroidChart中文翻譯)
第20節(jié). The DataSet class (general DataSet styling)(MPAndroidChart中文翻譯)
第21節(jié). DataSet subclasses (specific DataSet styling)(MPAndroidChart中文翻譯)
第22節(jié). The ViewPortHandler(MPAndroidChart中文翻譯)
第23節(jié). Customizing the Fill-Line-Position (FillFormatter)(MPAndroidChart中文翻譯)
第24節(jié). Proguard(MPAndroidChart中文翻譯)
第25節(jié). Realm.io mobile database(MPAndroidChart中文翻譯)
第26節(jié). Creating your own (custom) DataSets(MPAndroidChart中文翻譯)
第27節(jié). Miscellaneous (more useful stuff)(MPAndroidChart中文翻譯)
本依賴庫提供了很多修改視圖的方法(圖表的可見性,圖表的動畫).注意這些方法只對LInChart,BarChart,ScatterChart和CandleStickChart起作用.
下面提到這些方法都是有Chart類提供.其他修改視圖的方法是直接通過ViewPortHandler類(沒有圖表提供中間安全性).這只適用于熟悉API的高級用戶.
注意:在設(shè)置數(shù)據(jù)之后,需要調(diào)用圖表上所有修改視圖的方法.
Restraining what's visible(設(shè)置可見內(nèi)容)
- setVisibleXRangeMaximum(float maxXRange): 設(shè)置首次可見區(qū)域(x軸)的最大值.舉個栗子:如果設(shè)置值為10,在首次展示時,除非滾動,否則x軸上超過10個將不會顯示.
- setVisibleXRangeMinimum(float minXRange): 設(shè)置首次可見區(qū)域(x軸)的最小值.舉個栗子:如果設(shè)置值為10,在首次展示時,當(dāng)x軸上有10個值時想繼續(xù)放大是不可能的.
- setVisibleYRangeMaximum(float maxYRange, AxisDependency axis): 設(shè)置首次可見區(qū)域(y軸)的最大值.同時你需要設(shè)置你想應(yīng)用的是左,右哪個y軸.
- setViewPortOffsets(float left, float top, float right, float bottom): 為當(dāng)前視圖設(shè)置自定義偏移量(與實際圖表窗口的偏移量).設(shè)置這將組織圖表自動計算偏移量.調(diào)用 resetViewPortOffsets() 方法取消其設(shè)置.
只有在你知道你在做什么的時候才使用它
. - resetViewPortOffsets(): 重置通過setViewPortOffsets(...)方法設(shè)置的所有自定義偏移量.允許圖表再次自動計算所有偏移量.
- setExtraOffsets(float left, float top, float right, float bottom): 為自動計算完畢后的偏移量增加額外的偏移量(圖表視圖周圍).這個不會改變自動計算的偏移量,只會在原有基礎(chǔ)上增加空間.
Moving the view(where it is amied) (在有動畫的地方移動視圖)
- fitScreen(): 重置所有縮放和拖拽,使圖表完全合適邊框(完全縮小).
- moveViewToX(float xValue): 將當(dāng)前窗口的左側(cè)移動到指定的x軸位置
- moveViewToY(float yValue, AxisDependency axis): 將窗口居中所提供的y軸(左側(cè)還是右側(cè))上的指定y軸值.
- moveViewTo(float xValue, float yValue, AxisDependency axis):該方法將會將窗口的左側(cè)移動到指定x軸位置,居中于指定y軸的指定y軸值.(結(jié)合setVisibleXRange(...)和setVisibleYRange(...)方法才有意義)
- centerViewTo(float xValue, float yValue, AxisDependency axis): 該方法將會將窗口居中在x軸和y軸的指定坐標(biāo)位置.(結(jié)合 setVisibleXRange(...) 和setVisibleYRange(...)方法才有意義)
Moving the view with animations(用動畫移動視圖)
(v2.2.3正式版開始出現(xiàn))
- moveViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration): 該方法將窗口左側(cè)移動到x軸指定位置,居中于指定y軸的指定y軸值位置,并且伴隨著動畫形式.
- centerViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration): 該方法將窗口居中于x軸和y軸的指定位置,并伴隨動畫.
提醒: 所有的moveViewTo(...)方法都是自動調(diào)用刷新圖表的方法,無需額外調(diào)用invalidate()方法.
Zooming(programmatically) 縮放
- zoomIn(): 以圖表中心為縮放中心,放大1.4倍.
- zoomOut(): 以圖表中心為縮放中心,縮小0.7倍.
- zoom(float scaleX, float scaleY, float x, float y): 以x,y表示的坐標(biāo)點(單位px)為縮放中心,以scaleX和xcaleY為縮放因子進行縮放.記住縮放值為1時表示不縮放.
- zoom(float scaleX, float scaleY, float xValue, float yValue, AxisDependency axis):以x,y表示的實際數(shù)據(jù)點(非坐標(biāo)軸)為縮放中心,以scaleX和xcaleY為縮放因子進行縮放.記住縮放值為1時表示不縮放.
Zooming with animations 動畫縮放
(v2.2.3正式版本開始可用)
- zoomAndCenterAnimated(float scaleX, float scaleY, float xValue, float yValue, AxisDependency axis, long duration): 以指定的縮放因子進行縮放,并以動畫的方式將窗口居中于指定軸上的指定位置.
For example 舉個栗子
chart.setData(...); // first set data
// now modify viewport
chart.setVisibleXRangeMaximum(20); // allow 20 values to be displayed at once on the x-axis, not more
chart.moveViewToX(10); // set the left edge of the chart to x-index 10
// moveViewToX(...) also calls invalidate()