3
A
回答
3
我沒有想與圖書館混亂,所以我不得不延長几類,並覆蓋一些方法來滿足我的要求。我所做的是如下:
擴展X軸類並覆蓋:
private int mXAxisLabelBackgroundColor = Color.argb(200, 140, 234, 255);
/**
* boolen used to enable or disable label background, default is enabled
*/
private boolean mEnableLabelBackground = false;
public CustomXAxis(){
super();
}
public void setLabelBackgroundColor(int color){
mXAxisLabelBackgroundColor = color;
}
public void setLabelBackgroundColor(String colorHex){
mXAxisLabelBackgroundColor = Color.parseColor(colorHex);
}
public int getXAxisLabelBackgroundColor(){
return mXAxisLabelBackgroundColor;
}
/**
* Enable/disable X Axis label background, default is disabled.
* @param enable
*/
public void setDrawLabelBackground(boolean enable){
mEnableLabelBackground = enable;
}
/**
*
* @return boolean true if drawing label background is enabled otherwise false
*/
public boolean isDrawLabelBackgroundEnabled(){
return mEnableLabelBackground;
}
擴展XAxisRenderer並覆蓋drawLabels(帆布C,浮動POS)。在繪製標籤之前繪製一個矩形。
if (((CustomXAxis)mXAxis).isDrawLabelBackgroundEnabled()) {
drawLabelBackground(c);
}
擴展YAXIS和只需添加一個存取和mutator設置高於或低於柵格線的Y軸標籤。
private float mYLabelPosition = 0f;
public CustomYAxisRight(){
super(AxisDependency.RIGHT);
}
/**
* Sets the label position above or below the gridline.
* <p>use negative number to set label position above gridline.</p>
* @param position
*/
public void setYLabelPosition(float position){
mYLabelPosition = position;
}
public float getYLabelPosition(){
return mYLabelPosition;
}
擴展YAxisRenderer並重寫drawYLabels(帆布C,浮fixedPosition,浮[]的位置的浮式偏移)
c.drawText(text, fixedPosition, positions[i * 2 + 1] + (offset+((CustomYAxisRight)mYAxis).getYLabelPosition()), mAxisLabelPaint);
我也想顯示網格線爲Y軸標籤0當圖表開始從0.
覆蓋renderGridlines(Canvas c)並在繪製其他線條之前繪製一條線。
if (mYAxis.isStartAtZeroEnabled()) {
mTrans.pointValuesToPixel(position);
gridLinePath.moveTo(mViewPortHandler.offsetLeft(), mViewPortHandler.contentBottom() - 1f);
gridLinePath.lineTo(mViewPortHandler.contentRight(), mViewPortHandler.contentBottom() - 1f);
// draw a path because lines don't support dashing on lower android versions
c.drawPath(gridLinePath, mGridPaint);
gridLinePath.reset();
}
最後延長線型圖並重寫:
@Override
protected void init() {
super.init();
mAxisRight = new CustomYAxisRight();
mXAxis = new CustomXAxis();
mAxisRendererRight = new CustomYAxisRenderer(mViewPortHandler,mAxisRight,mRightAxisTransformer);
mXAxisRenderer = new CustomXAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer);
}
@Override
public void setViewPortOffsets(final float left, final float top, final float right, final float bottom) {
mCustomViewPortEnabled = true;
if (((CustomXAxis)mXAxis).isDrawLabelBackgroundEnabled()){
if (bottom == 0){
//we have to leave a space for the labels to draw
_bottomOffset = 80f;
}
}
post(new Runnable() {
@Override
public void run() {
mViewPortHandler.restrainViewPort(left, top, right, _bottomOffset);
prepareOffsetMatrix();
prepareValuePxMatrix();
}
});
}
相關問題
- 1. 如何將字符串標籤添加到MPAndroidCharts
- 2. 如何將背景添加到錨標籤?
- 3. 將背景顏色設置爲HighChart xAxis標籤
- 4. 如何將背景顏色添加到IKImageBrowserCell的標題標籤中?
- 5. 如何添加背景文本到textarea標籤?
- 6. 如何將OnClickListener添加到背景?
- 7. 將背景顏色添加到Extjs中的標籤中
- 8. 使用sed將標籤添加到背景顏色?
- 9. 如何將背景圖像添加到簽名板
- 10. 將標籤添加到散景圖
- 11. 將背景添加到IKImageView
- 12. 如何將背景陰影添加到網站背景?
- 13. 如何使用Swift將背景圖片和標籤添加到UIBarButtonItem中
- 14. 將背景圖像和背景顏色對添加到元素
- 15. 我如何將背景圖片添加到我的標題中?
- 16. 如何將標籤添加到散景條形圖?
- 17. 如何爲xAxis工具欄中的標籤添加值?
- 18. 如何在ios圖表中爲BarChartView的XAxis添加標籤
- 19. 如何將標籤添加到繪圖
- 20. 如何將標籤添加到THREE.MESH?
- 21. 如何將圖像添加到標籤?
- 22. 如何將標籤添加到SlidingTabLayout?
- 23. 如何將新標籤添加到JTidy?
- 24. 如何將標籤添加到情節
- 25. 如何將actionlistener添加到JRadioButton標籤?
- 26. 如何將文本添加到UILabel背景圖像
- 27. 如何將字符串標籤(xAxis標籤)添加到圖表框架中的水平條上
- 28. 如何將TITLE和ALT添加到背景圖片(CSS Sprites)?
- 29. 如何將顏色疊加層添加到背景圖像?
- 30. 將背景圖像添加到現有的背景圖像