use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class DySplineChart method chart2Render.
private void chart2Render() {
try {
// chart2.setApplyBackgroundColor(true);
// chart2.setBackgroundColor(Color.GREEN);
// 数据源
chart2.setCategories(labels2);
chart2.setDataSource(chartData2);
// 坐标系
// 数据轴最大值
chart2.getDataAxis().setAxisMax(100);
// chart2.getDataAxis().setAxisMin(0);
// 数据轴刻度间隔
chart2.getDataAxis().setAxisSteps(20);
// 标签轴最大值
// 60秒
chart2.setCategoryAxisMax(CHART2_X_TIME);
// 标签轴最小值
chart2.setCategoryAxisMin(0);
chart2.getDataAxis().getAxisPaint().setColor(Color.rgb(127, 204, 204));
chart2.getCategoryAxis().getAxisPaint().setColor(Color.rgb(127, 204, 204));
chart2.getDataAxis().getTickMarksPaint().setColor(Color.rgb(127, 204, 204));
chart2.getCategoryAxis().getTickMarksPaint().setColor(Color.rgb(127, 204, 204));
// 居中
chart2.getDataAxis().setHorizontalTickAlign(Align.CENTER);
chart2.getDataAxis().getTickLabelPaint().setTextAlign(Align.CENTER);
// 居中显示轴
chart2.setDataAxisLocation(XEnum.AxisLocation.VERTICAL_CENTER);
chart2.setCategoryAxisLocation(XEnum.AxisLocation.HORIZONTAL_CENTER);
chart2.getPlotLegend().hide();
chart2.disableScale();
chart2.setPlotPanMode(XEnum.PanMode.HORIZONTAL);
// chart2.getDataAxis().hideAxisLine();
chart2.getDataAxis().hideTickMarks();
chart2.getPlotGrid().showHorizontalLines();
chart2.getPlotGrid().showVerticalLines();
// 定义数据轴标签显示格式
chart2.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
Double tmp = Double.parseDouble(value);
String label = "";
if (tmp == 0 || tmp <= chart2.getDataAxis().getAxisMin()) {
label = tmp.toString();
} else {
Integer k = (int) (tmp % 20);
if (0 == k) {
DecimalFormat df = new DecimalFormat("#0");
label = df.format(tmp).toString();
}
}
return label;
}
});
// 激活点击监听
chart2.ActiveListenItemClick();
// 为了让触发更灵敏,可以扩大5px的点击监听范围
chart2.extPointClickRange(5);
chart2.showClikedFocus();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(TAG, e.toString());
}
}
use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class ScatterChart01View method chartRender.
private void chartRender() {
try {
// 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
int[] ltrb = getBarLnDefaultSpadding();
chart.setPadding(15, ltrb[1], 15, ltrb[3]);
// 数据源
chart.setCategories(labels);
chart.setDataSource(chartData);
// 坐标系
// 数据轴最大值
chart.getDataAxis().setAxisMax(100);
// chart.getDataAxis().setAxisMin(0);
// 数据轴刻度间隔
chart.getDataAxis().setAxisSteps(10);
// 标签轴最大值
chart.setCategoryAxisMax(7);
// 标签轴最小值
chart.setCategoryAxisMin(1);
chart.getDataAxis().setHorizontalTickAlign(Align.CENTER);
chart.getDataAxis().getTickLabelPaint().setTextAlign(Align.CENTER);
// chart.getDataAxis().setDetailModeSteps(4);
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().getTickLabelPaint().setTextAlign(Align.LEFT);
// 定义交叉点标签显示格式,特别备注,因曲线图的特殊性,所以返回格式为: x值,y值
// 请自行分析定制
chart.setDotLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
String label = "(" + value + ")";
return (label);
}
});
// 标题
chart.setTitle("散点图");
chart.addSubtitle("(XCL-Charts Demo)");
// 激活点击监听
chart.ActiveListenItemClick();
// 为了让触发更灵敏,可以扩大5px的点击监听范围
chart.extPointClickRange(10);
chart.getPointPaint().setStrokeWidth(6);
// 显示十字交叉线
chart.showDyLine();
chart.getDyLine().setDyLineStyle(XEnum.DyLineStyle.BackwardDiagonal);
// 背景渐变
chart.getPlotArea().setBackgroundColor(true, Color.rgb(83, 182, 203));
chart.getPlotArea().setApplayGradient(true);
chart.getPlotArea().setGradientDirection(XEnum.Direction.HORIZONTAL);
chart.getPlotArea().setBeginColor(Color.WHITE);
// 图例
chart.getPlotLegend().setType(XEnum.LegendType.COLUMN);
chart.getPlotLegend().setVerticalAlign(XEnum.VerticalAlign.MIDDLE);
chart.getPlotLegend().setHorizontalAlign(XEnum.HorizontalAlign.RIGHT);
chart.getPlotLegend().getBox().setBorderRectType(XEnum.RectType.RECT);
chart.getPlotLegend().showBox();
// chart.disablePanMode();
chart.disableScale();
// 不使用精确计算,忽略Java计算误差
chart.disableHighPrecision();
/*
//定义交叉点标签显示格式,特别备注,因图的特殊性,所以返回格式为: x值,y值
//请自行分析定制
chart.setDotLabelFormatter(new IFormatterTextCallBack(){
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
String label = "("+value+")";
return (label);
}
});*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(TAG, e.toString());
}
}
use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class DySplineChart method chartRender.
private void chartRender() {
try {
// chart1.setApplyBackgroundColor(true);
// chart1.setBackgroundColor(Color.RED);
// 数据源
chart1.setCategories(labels);
chart1.setDataSource(chartData);
// 坐标系
// 数据轴最大值
chart1.getDataAxis().setAxisMax(240);
chart1.getDataAxis().setAxisMin(30);
// 数据轴刻度间隔
chart1.getDataAxis().setAxisSteps(10);
// 标签轴最大值
// 120秒
chart1.setCategoryAxisMax(CHART1_X_TIME);
// 标签轴最小值
chart1.setCategoryAxisMin(0);
chart1.getDataAxis().getAxisPaint().setColor(Color.rgb(127, 204, 204));
chart1.getCategoryAxis().getAxisPaint().setColor(Color.rgb(127, 204, 204));
chart1.getDataAxis().getTickMarksPaint().setColor(Color.rgb(127, 204, 204));
chart1.getCategoryAxis().getTickMarksPaint().setColor(Color.rgb(127, 204, 204));
// 居中
chart1.getDataAxis().setHorizontalTickAlign(Align.CENTER);
chart1.getDataAxis().getTickLabelPaint().setTextAlign(Align.CENTER);
// 居中显示轴
chart1.setDataAxisLocation(XEnum.AxisLocation.VERTICAL_CENTER);
chart1.setCategoryAxisLocation(XEnum.AxisLocation.HORIZONTAL_CENTER);
// 标题
// chart1.setTitle("Spline Chart");
// chart1.addSubtitle("(XCL-Charts Demo)");
chart1.getPlotLegend().hide();
chart1.disableScale();
chart1.setPlotPanMode(XEnum.PanMode.HORIZONTAL);
chart1.setCrurveLineStyle(XEnum.CrurveLineStyle.BEELINE);
// chart1.getDataAxis().hideAxisLine();
chart1.getDataAxis().hideTickMarks();
chart1.getPlotGrid().showHorizontalLines();
chart1.getPlotGrid().showVerticalLines();
// 定义数据轴标签显示格式
chart1.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
Double tmp = Double.parseDouble(value);
String label = "";
if (tmp == 0 || tmp <= chart1.getDataAxis().getAxisMin()) {
label = tmp.toString();
} else {
Integer k = (int) (tmp % 30);
if (0 == k) {
DecimalFormat df = new DecimalFormat("#0");
label = df.format(tmp).toString();
}
}
return label;
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(TAG, e.toString());
}
}
use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class MultiAxisChart02View method renderLnAxis.
/**
* 折线图轴相关
*/
private void renderLnAxis() {
// 标签轴
lnChart.setCategories(chartLabelsLn);
lnChart.getCategoryAxis().hide();
// 设定数据源
lnChart.setDataSource(chartDataLn);
// 数据轴
lnChart.setDataAxisLocation(XEnum.AxisLocation.RIGHT);
DataAxis dataAxis = lnChart.getDataAxis();
dataAxis.setAxisMax(135);
dataAxis.setAxisMin(0);
dataAxis.setAxisSteps(15);
dataAxis.getAxisPaint().setColor(Color.rgb(51, 204, 204));
dataAxis.getTickMarksPaint().setColor(Color.rgb(51, 204, 204));
// 定制数据轴上的标签格式
lnChart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
double label = Double.parseDouble(value);
DecimalFormat df = new DecimalFormat("#0");
return df.format(label).toString();
}
});
// 允许线与轴交叉时,线会断开
lnChart.setLineAxisIntersectVisible(false);
// 调整右轴显示风格
lnChart.getDataAxis().setHorizontalTickAlign(Align.RIGHT);
lnChart.getDataAxis().getTickLabelPaint().setTextAlign(Align.LEFT);
lnChart.setXCoordFirstTickmarksBegin(true);
//
lnChart.setBarCenterStyle(XEnum.BarCenterStyle.SPACE);
}
use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class SplineChart02View method chartRender.
private void chartRender() {
try {
// 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
int[] ltrb = getBarLnDefaultSpadding();
chart.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
// 显示边框
chart.showRoundBorder();
// 数据源
chart.setCategories(labels);
chart.setDataSource(chartData);
// 坐标系
// 数据轴最大值
chart.getDataAxis().setAxisMax(1);
chart.getDataAxis().setAxisMin(-1);
// 数据轴刻度间隔
chart.getDataAxis().setAxisSteps(0.5f);
// 标签轴最大值
chart.setCategoryAxisMax(360);
// 标签轴最小值
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(plot.getHorizontalLinePaint().getColor());
chart.getCategoryAxis().getAxisPaint().setColor(plot.getHorizontalLinePaint().getColor());
chart.getDataAxis().getTickMarksPaint().setColor(plot.getHorizontalLinePaint().getColor());
chart.getCategoryAxis().getTickMarksPaint().setColor(plot.getHorizontalLinePaint().getColor());
// 定义交叉点标签显示格式,特别备注,因曲线图的特殊性,所以返回格式为: x值,y值
// 请自行分析定制
chart.setDotLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
String label = "(" + value + ")";
return (label);
}
});
// 标题
chart.setTitle("三角函数曲线图");
chart.addSubtitle("(XCL-Charts Demo)");
// 激活点击监听
// chart.ActiveListenItemClick();
// 为了让触发更灵敏,可以扩大5px的点击监听范围
// chart.extPointClickRange(5);
// chart.showClikedFocus();
// 不使用精确误差计算,速度提升明显
chart.disableHighPrecision();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(TAG, e.toString());
}
}
Aggregations