1
A
回答
1
這是目前(2014年8月5日)不可能在the original GraphView library。
我需要這個功能,所以我分叉庫並自己實現了這些功能。您可以在我的叉子的feature/series_specific_styles
分支找到更新的代碼:
希望在將來的這些變化將被拉入到原來的庫。
實際的代碼更改相對簡單。
添加所需的背景領域
GraphViewSeries.GraphViewSeriesStyle
更新
LineGraphView.drawSeries()
尋找這些領域,而不是依靠自身的內在價值。
我已經包含下面全更新,但要查看它們是提交頁面上的最簡單的方法:
這裏是更新GraphViewSeriesStyle
類:
static public class GraphViewSeriesStyle {
public int color = 0xff0077cc;
public int thickness = 3;
private ValueDependentColor valueDependentColor;
private final Paint paintBackground;
private boolean drawBackground;
private boolean drawDataPoints;
private float dataPointsRadius = 10f;
public GraphViewSeriesStyle() {
super();
paintBackground = new Paint();
paintBackground.setColor(Color.rgb(20, 40, 60));
paintBackground.setStrokeWidth(4);
paintBackground.setAlpha(128);
}
public GraphViewSeriesStyle(int color, int thickness) {
super();
this.color = color;
this.thickness = thickness;
paintBackground = new Paint();
paintBackground.setColor(Color.rgb(20, 40, 60));
paintBackground.setStrokeWidth(4);
paintBackground.setAlpha(128);
}
public ValueDependentColor getValueDependentColor() {
return valueDependentColor;
}
/**
* the color depends on the value of the data.
* only possible in BarGraphView
* @param valueDependentColor
*/
public void setValueDependentColor(ValueDependentColor valueDependentColor) {
this.valueDependentColor = valueDependentColor;
}
public boolean getDrawBackground() {
return drawBackground;
}
public void setDrawBackground(boolean drawBackground) {
this.drawBackground = drawBackground;
}
public Paint getPaintBackground() {
return paintBackground;
}
public int getBackgroundColor() {
return paintBackground.getColor();
}
/**
* sets the background colour for the series. This is not the background
* colour of the whole graph.
*/
public void setBackgroundColor(int color) {
paintBackground.setColor(color);
}
public float getDataPointsRadius() {
return dataPointsRadius;
}
public boolean getDrawDataPoints() {
return drawDataPoints;
}
/**
* sets the radius of the circles at the data points.
* @see #setDrawDataPoints(boolean)
* @param dataPointsRadius
*/
public void setDataPointsRadius(float dataPointsRadius) {
this.dataPointsRadius = dataPointsRadius;
}
/**
* You can set the flag to let the GraphView draw circles at the data points
* @see #setDataPointsRadius(float)
* @param drawDataPoints
*/
public void setDrawDataPoints(boolean drawDataPoints) {
this.drawDataPoints = drawDataPoints;
}
}
這裏是更新LineGraphView.drawSeries()
方法:
public void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float graphwidth, float graphheight, float border, double minX, double minY, double diffX, double diffY, float horstart, GraphViewSeriesStyle style) {
// draw background
double lastEndY = 0;
double lastEndX = 0;
// draw data
paint.setStrokeWidth(style.thickness);
paint.setColor(style.color);
Path bgPath = null;
if ((drawBackground) || (style.getDrawBackground())) {
bgPath = new Path();
}
lastEndY = 0;
lastEndX = 0;
float firstX = 0;
for (int i = 0; i < values.length; i++) {
double valY = values[i].getY() - minY;
double ratY = valY/diffY;
double y = graphheight * ratY;
double valX = values[i].getX() - minX;
double ratX = valX/diffX;
double x = graphwidth * ratX;
if (i > 0) {
float startX = (float) lastEndX + (horstart + 1);
float startY = (float) (border - lastEndY) + graphheight;
float endX = (float) x + (horstart + 1);
float endY = (float) (border - y) + graphheight;
// draw data point
if (drawDataPoints) {
//fix: last value was not drawn. Draw here now the end values
canvas.drawCircle(endX, endY, dataPointsRadius, paint);
} else if (style.getDrawDataPoints()) {
canvas.drawCircle(endX, endY, style.getDataPointsRadius(), paint);
}
canvas.drawLine(startX, startY, endX, endY, paint);
if (bgPath != null) {
if (i==1) {
firstX = startX;
bgPath.moveTo(startX, startY);
}
bgPath.lineTo(endX, endY);
}
} else if ((drawDataPoints) || (style.getDrawDataPoints())) {
//fix: last value not drawn as datapoint. Draw first point here, and then on every step the end values (above)
float first_X = (float) x + (horstart + 1);
float first_Y = (float) (border - y) + graphheight;
if (drawDataPoints) {
canvas.drawCircle(first_X, first_Y, dataPointsRadius, paint);
} else if (style.getDrawDataPoints()) {
canvas.drawCircle(first_X, first_Y, style.getDataPointsRadius(), paint);
}
}
lastEndY = y;
lastEndX = x;
}
if (bgPath != null) {
// end/close path
bgPath.lineTo((float) lastEndX, graphheight + border);
bgPath.lineTo(firstX, graphheight + border);
bgPath.close();
if (style.getDrawBackground()) {
canvas.drawPath(bgPath, style.getPaintBackground());
} else {
canvas.drawPath(bgPath, paintBackground);
}
}
}
對於利息,該分支也允許數據點被配置爲每個系列 - 代碼改變這裏可見:
相關問題
- 1. 在安卓graphview添加背景圖片
- 2. GraphView庫刪除系列
- 3. Android GraphView條形圖多個系列
- 4. 與costum背景每個列表項
- 5. 如何在沒有背景的GraphView中繪製圖表?
- 6. Android GraphView不顯示系列標題
- 7. 更改TAchart系列的背景顏色
- 8. 每個列表元素的「a」個體背景?
- 9. 半頁背景/列背景
- 10. Android GraphView多個系列顯示/隱藏特定的線圖
- 11. 每個MDlite卡的新背景圖片
- 12. 設置每個gridView項目的背景?
- 13. Android ListView背景在每個條目後重復背景
- 14. 圖像作爲每個SectionView的每個TableView的背景?
- 15. RecyclerView:更改每個列表上Textview的背景顏色項目
- 16. 離子框架:每個列表項的不同背景顏色
- 17. 圖表系列:每個系列一列?
- 18. 如何更改android背景每個???秒?
- 19. 每個點擊動畫背景位置
- 20. Highcharts每個系列的tooltipformat?
- 21. 設計WPF佈局網格背景(每個單元格,行,列)
- 22. Highcharts每個系列的一個值列
- 23. xCode Sprite-Kit - 每個場景中的背景圖像
- 24. 邊境改變背景顏色的每個系統的顏色改變
- 25. Kendo UI下拉列表 - 每個列表項目的不同背景顏色
- 26. 前景背景系統和實時操作系統的區別
- 27. 背景的列表視圖
- 28. GridLayoutManager每行相同的背景
- 29. 多個地塊中每個地塊的單獨背景顏色
- 30. Android列表背景與單獨列表項目背景重疊