use of org.xclcharts.renderer.info.AnchorDataPoint in project XCL-Charts by xcltapestry.
the class SplineChart01View method chartRender.
private void chartRender() {
try {
//设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
int[] ltrb = getBarLnDefaultSpadding();
chart.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
//平移时收缩下
//float margin = DensityUtil.dip2px(getContext(), 20);
//chart.setXTickMarksOffsetMargin(margin);
//显示边框
chart.showRoundBorder();
//数据源
chart.setCategories(labels);
chart.setDataSource(chartData);
//坐标系
//数据轴最大值
chart.getDataAxis().setAxisMax(100);
//chart.getDataAxis().setAxisMin(0);
//数据轴刻度间隔
chart.getDataAxis().setAxisSteps(10);
//标签轴最大值
chart.setCategoryAxisMax(10);
//标签轴最小值
chart.setCategoryAxisMin(0);
//设置图的背景色
//chart.setBackgroupColor(true,Color.BLACK);
//设置绘图区的背景色
//chart.getPlotArea().setBackgroupColor(true, Color.WHITE);
//背景网格
PlotGrid plot = chart.getPlotGrid();
plot.showHorizontalLines();
plot.showVerticalLines();
plot.getHorizontalLinePaint().setStrokeWidth(3);
plot.getHorizontalLinePaint().setColor(Color.rgb(127, 204, 204));
plot.setHorizontalLineStyle(XEnum.LineStyle.DOT);
//把轴线设成和横向网络线一样和大小和颜色,演示下定制性,这块问得人较多
//chart.getDataAxis().getAxisPaint().setStrokeWidth(
// plot.getHorizontalLinePaint().getStrokeWidth());
//chart.getCategoryAxis().getAxisPaint().setStrokeWidth(
// plot.getHorizontalLinePaint().getStrokeWidth());
chart.getDataAxis().getAxisPaint().setColor(Color.rgb(127, 204, 204));
chart.getCategoryAxis().getAxisPaint().setColor(Color.rgb(127, 204, 204));
chart.getDataAxis().getTickMarksPaint().setColor(Color.rgb(127, 204, 204));
chart.getCategoryAxis().getTickMarksPaint().setColor(Color.rgb(127, 204, 204));
//居中
chart.getDataAxis().setHorizontalTickAlign(Align.CENTER);
chart.getDataAxis().getTickLabelPaint().setTextAlign(Align.CENTER);
//居中显示轴
//plot.hideHorizontalLines();
//plot.hideVerticalLines();
//chart.setDataAxisLocation(XEnum.AxisLocation.VERTICAL_CENTER);
//chart.setCategoryAxisLocation(XEnum.AxisLocation.HORIZONTAL_CENTER);
//定义交叉点标签显示格式,特别备注,因曲线图的特殊性,所以返回格式为: x值,y值
//请自行分析定制
chart.setDotLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
String label = "(" + value + ")";
return (label);
}
});
//标题
chart.setTitle("Spline Chart");
chart.addSubtitle("(XCL-Charts Demo)");
//激活点击监听
chart.ActiveListenItemClick();
//为了让触发更灵敏,可以扩大5px的点击监听范围
chart.extPointClickRange(5);
chart.showClikedFocus();
//显示十字交叉线
chart.showDyLine();
chart.getDyLine().setDyLineStyle(XEnum.DyLineStyle.Vertical);
//扩大实际绘制宽度
//chart.getPlotArea().extWidth(500.f);
//封闭轴
chart.setAxesClosed(true);
//将线显示为直线,而不是平滑的
chart.setCrurveLineStyle(XEnum.CrurveLineStyle.BEELINE);
//不使用精确计算,忽略Java计算误差,提高性能
chart.disableHighPrecision();
//仅能横向移动
chart.setPlotPanMode(XEnum.PanMode.HORIZONTAL);
//批注
List<AnchorDataPoint> mAnchorSet = new ArrayList<AnchorDataPoint>();
AnchorDataPoint an1 = new AnchorDataPoint(2, 0, XEnum.AnchorStyle.CAPROUNDRECT);
an1.setAlpha(200);
an1.setBgColor(Color.RED);
an1.setAreaStyle(XEnum.DataAreaStyle.FILL);
AnchorDataPoint an2 = new AnchorDataPoint(1, 1, XEnum.AnchorStyle.CIRCLE);
an2.setBgColor(Color.GRAY);
AnchorDataPoint an3 = new AnchorDataPoint(0, 2, XEnum.AnchorStyle.RECT);
an3.setBgColor(Color.BLUE);
mAnchorSet.add(an1);
mAnchorSet.add(an2);
mAnchorSet.add(an3);
chart.setAnchorDataPoint(mAnchorSet);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(TAG, e.toString());
}
}
use of org.xclcharts.renderer.info.AnchorDataPoint in project XCL-Charts by xcltapestry.
the class XChart method drawAnchor.
/**
* 绘制批注
* @param anchorSet 批注集合
* @param dataID 主数据集id
* @param childID 子数据集id
* @param canvas 画布
* @param x X坐标点
* @param y y坐标点
* @return 是否有绘制
*/
protected boolean drawAnchor(List<AnchorDataPoint> anchorSet, int dataID, int childID, Canvas canvas, float x, float y, float radius) {
if (null == anchorSet || -1 == dataID)
return false;
int count = anchorSet.size();
float left = getPlotArea().getLeft();
float right = getPlotArea().getRight();
float top = getPlotArea().getTop();
float bottom = getPlotArea().getBottom();
for (int i = 0; i < count; i++) {
AnchorDataPoint an = anchorSet.get(i);
if (an.getDataSeriesID() == dataID) {
if ((-1 == childID || -1 == an.getDataChildID()) || (-1 != childID && an.getDataChildID() == childID)) {
AnchorRender.getInstance().renderAnchor(canvas, an, x, y, radius, left, top, right, bottom);
return true;
}
}
}
return false;
}
use of org.xclcharts.renderer.info.AnchorDataPoint in project XCL-Charts by xcltapestry.
the class SplineChart05View method chartAnchor.
private void chartAnchor() {
//激活点击监听
chart.ActiveListenItemClick();
//为了让触发更灵敏,可以扩大5px的点击监听范围
chart.extPointClickRange(5);
chart.showClikedFocus();
//批注
List<AnchorDataPoint> mAnchorSet = new ArrayList<AnchorDataPoint>();
AnchorDataPoint an2 = new AnchorDataPoint(0, 0, XEnum.AnchorStyle.TOBOTTOM);
an2.setBgColor(Color.GRAY);
//an2.setAnchorStyle(XEnum.AnchorStyle.CIRCLE);
an2.setLineStyle(XEnum.LineStyle.DOT);
AnchorDataPoint an3 = new AnchorDataPoint(0, 1, XEnum.AnchorStyle.TOBOTTOM);
an3.setBgColor(Color.RED);
//an3.setAnchorStyle(XEnum.AnchorStyle.RECT);
an3.setAreaStyle(XEnum.DataAreaStyle.STROKE);
an3.setLineStyle(XEnum.LineStyle.DOT);
//从点到底的标识线
//从点到底的标识线
AnchorDataPoint an4 = new AnchorDataPoint(0, 2, XEnum.AnchorStyle.TOBOTTOM);
an4.setBgColor(Color.WHITE);
an4.setLineWidth(15);
an4.setLineStyle(XEnum.LineStyle.DOT);
AnchorDataPoint an5 = new AnchorDataPoint(0, 3, XEnum.AnchorStyle.TOBOTTOM);
an5.setBgColor(Color.WHITE);
an5.setLineWidth(15);
an5.setLineStyle(XEnum.LineStyle.DASH);
AnchorDataPoint an6 = new AnchorDataPoint(0, 4, XEnum.AnchorStyle.TOBOTTOM);
an6.setBgColor(Color.RED);
an6.setLineWidth(15);
an6.setLineStyle(XEnum.LineStyle.DOT);
AnchorDataPoint an7 = new AnchorDataPoint(0, 5, XEnum.AnchorStyle.TOBOTTOM);
an7.setBgColor(Color.WHITE);
an7.setLineWidth(15);
an7.setLineStyle(XEnum.LineStyle.DASH);
mAnchorSet.add(an2);
mAnchorSet.add(an3);
mAnchorSet.add(an4);
mAnchorSet.add(an5);
mAnchorSet.add(an6);
mAnchorSet.add(an7);
chart.setAnchorDataPoint(mAnchorSet);
}
use of org.xclcharts.renderer.info.AnchorDataPoint in project XCL-Charts by xcltapestry.
the class LineChart02View method chartDataSet.
private void chartDataSet() {
//Line 1
LinkedList<Double> dataSeries1 = new LinkedList<Double>();
dataSeries1.add(400d);
dataSeries1.add(480d);
dataSeries1.add(500d);
dataSeries1.add(560d);
LineData lineData1 = new LineData("单间(5层光线好)", dataSeries1, Color.rgb(234, 83, 71));
lineData1.setDotStyle(XEnum.DotStyle.DOT);
//Line 2
LinkedList<Double> dataSeries2 = new LinkedList<Double>();
dataSeries2.add(0d);
dataSeries2.add(0d);
dataSeries2.add(0d);
dataSeries2.add(0d);
dataSeries2.add((double) 800);
dataSeries2.add((double) 950);
dataSeries2.add((double) 1200);
LineData lineData2 = new LineData("一房一厅(3层无光线)", dataSeries2, Color.rgb(75, 166, 51));
lineData2.setDotStyle(XEnum.DotStyle.PRISMATIC);
lineData2.getPlotLine().getDotPaint().setColor(Color.rgb(234, 142, 43));
lineData2.getDotLabelPaint().setColor(Color.rgb(234, 142, 43));
lineData2.setLabelVisible(true);
lineData2.getLabelOptions().getBox().getBackgroundPaint().setColor(Color.rgb(76, 76, 76));
//lineData2.getPlotLabel().hideBox();
//Line 3
LinkedList<Double> dataSeries3 = new LinkedList<Double>();
dataSeries3.add(0d);
dataSeries3.add(0d);
dataSeries3.add(0d);
dataSeries3.add(0d);
dataSeries3.add(0d);
dataSeries3.add(0d);
dataSeries3.add(0d);
dataSeries3.add(630d);
dataSeries3.add(710d);
LineData lineData3 = new LineData("单间(9层无电梯)", dataSeries3, Color.rgb(123, 89, 168));
lineData3.setDotStyle(XEnum.DotStyle.DOT);
//轴上分界线的交叉点
LinkedList<Double> dataSeries4 = new LinkedList<Double>();
dataSeries4.add(1500d);
LinkedList<Double> dataSeries5 = new LinkedList<Double>();
dataSeries5.add(3000d);
LinkedList<Double> dataSeries6 = new LinkedList<Double>();
dataSeries6.add(calcAvg());
LineData lineData4 = new LineData("", dataSeries4, Color.rgb(35, 172, 57));
lineData4.setDotStyle(XEnum.DotStyle.RECT);
LineData lineData5 = new LineData("", dataSeries5, Color.rgb(69, 181, 248));
lineData5.setDotStyle(XEnum.DotStyle.RECT);
LineData lineData6 = new LineData("", dataSeries6, Color.rgb(251, 79, 128));
lineData6.setDotStyle(XEnum.DotStyle.TRIANGLE);
chartData.add(lineData1);
chartData.add(lineData2);
chartData.add(lineData3);
chartData.add(lineData4);
chartData.add(lineData5);
chartData.add(lineData6);
//批注
//List<AnchorDataPoint> mAnchorSet = new ArrayList<AnchorDataPoint>();
AnchorDataPoint an4 = new AnchorDataPoint(0, 2, XEnum.AnchorStyle.CAPRECT);
an4.setAnchor("批注");
an4.setBgColor(Color.rgb(255, 145, 126));
mAnchorSet.add(an4);
chart.setAnchorDataPoint(mAnchorSet);
}
use of org.xclcharts.renderer.info.AnchorDataPoint in project XCL-Charts by xcltapestry.
the class LineChart03View method chartRender.
@SuppressLint("NewApi")
private void chartRender() {
try {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
//setLayerType(View.LAYER_TYPE_NONE, null);
//设定数据源
chart.setCategories(labels);
chart.setDataSource(chartData);
//数据轴最大值
chart.getDataAxis().setAxisMax(100);
//数据轴刻度间隔
chart.getDataAxis().setAxisSteps(10);
//chart.getDataAxis().setAxisLineVisible(false);
chart.getDataAxis().hide();
chart.getCategoryAxis().getTickLabelPaint().setTextAlign(Align.LEFT);
chart.getCategoryAxis().setTickLabelRotateAngle(90);
chart.getAxisTitle().setLowerTitle("(年份)");
//chart.hideRightAxis();
//chart.hideTopAxis();
chart.getPlotLegend().hide();
//忽略Java的float计算误差
chart.disableHighPrecision();
//批注
List<AnchorDataPoint> mAnchorSet = new ArrayList<AnchorDataPoint>();
AnchorDataPoint an1 = new AnchorDataPoint(2, 0, XEnum.AnchorStyle.RECT);
an1.setAlpha(200);
an1.setBgColor(Color.RED);
an1.setAreaStyle(XEnum.DataAreaStyle.FILL);
AnchorDataPoint an2 = new AnchorDataPoint(1, 1, XEnum.AnchorStyle.CIRCLE);
an2.setBgColor(Color.GRAY);
AnchorDataPoint an3 = new AnchorDataPoint(0, 2, XEnum.AnchorStyle.RECT);
an3.setBgColor(Color.BLUE);
mAnchorSet.add(an1);
mAnchorSet.add(an2);
mAnchorSet.add(an3);
chart.setAnchorDataPoint(mAnchorSet);
//禁掉平移,这样线上的标注框在最左和最右时才能显示全
chart.disablePanMode();
} catch (Exception e) {
// TODO Auto-generated catch block
Log.e(TAG, e.toString());
}
}
Aggregations