use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class MultiAxisChart01View method renderBarAxis.
/**
* 柱形图轴相关
*/
private void renderBarAxis() {
// 标签轴
chart.setCategories(chartLabels);
// 数据轴
chart.setDataSource(chartDataset);
chart.getDataAxis().setAxisMax(90000);
chart.getDataAxis().setAxisSteps(10000);
// 定制数据轴上的标签格式
chart.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();
}
});
// 定制标签轴标签的标签格式
CategoryAxis categoryAxis = chart.getCategoryAxis();
categoryAxis.setTickLabelRotateAngle(-15f);
categoryAxis.getTickLabelPaint().setTextSize(15);
categoryAxis.getTickLabelPaint().setTextAlign(Align.CENTER);
categoryAxis.setLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// String tmp = "c-["+value+"]";
return value;
}
});
chart.getPlotGrid().hideEvenRowBgColor();
chart.getPlotGrid().hideHorizontalLines();
chart.getPlotGrid().hideOddRowBgColor();
chart.getPlotGrid().hideVerticalLines();
chart.setBarCenterStyle(XEnum.BarCenterStyle.TICKMARKS);
// chart.getCategoryAxis().hideAxisLabels();
}
use of org.xclcharts.common.IFormatterTextCallBack 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.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class BarChart04View 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.setTitle("BMI自测");
chart.addSubtitle("(XCL-Charts Demo)");
// 数据源
chart.setDataSource(chartData);
chart.setCategories(chartLabels);
chart.setCustomLines(mCustomLineDataset);
// 图例
chart.getAxisTitle().setLeftTitle("参考成年男性标准值");
chart.getAxisTitle().setLowerTitle("(请不要忽视您的健康)");
// 数据轴
chart.getDataAxis().setAxisMax(40);
chart.getDataAxis().setAxisMin(0);
chart.getDataAxis().setAxisSteps(5);
// 指隔多少个轴刻度(即细刻度)后为主刻度
chart.getDataAxis().setDetailModeSteps(2);
// 背景网格
chart.getPlotGrid().showHorizontalLines();
// 定义数据轴标签显示格式
chart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
Double tmp = Double.parseDouble(value);
DecimalFormat df = new DecimalFormat("#0");
String label = df.format(tmp).toString();
return (label);
}
});
// 标签旋转45度
chart.getCategoryAxis().setTickLabelRotateAngle(45f);
chart.getCategoryAxis().getTickLabelPaint().setTextSize(15);
// 在柱形顶部显示值
chart.getBar().setItemLabelVisible(true);
// 设定格式
chart.setItemLabelFormatter(new IFormatterDoubleCallBack() {
@Override
public String doubleFormatter(Double value) {
// TODO Auto-generated method stub
DecimalFormat df = new DecimalFormat("#0");
String label = df.format(value).toString();
return label;
}
});
// 隐藏Key
chart.getPlotLegend().hide();
// 让柱子间没空白
// 可尝试0.1或0.5各有啥效果噢
chart.getBar().setBarInnerMargin(0.1f);
// 禁用平移模式
chart.disablePanMode();
// 提高性能
chart.disableHighPrecision();
// 柱形和标签居中方式
chart.setBarCenterStyle(XEnum.BarCenterStyle.TICKMARKS);
chart.getDataAxis().setAxisLineStyle(XEnum.AxisLineStyle.FILLCAP);
chart.getCategoryAxis().setAxisLineStyle(XEnum.AxisLineStyle.FILLCAP);
// chart.showRoundBorder();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class BarChart06View 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.setDataSource(chartData);
// 数据源
chart.setCategories(chartLabels);
// 数据轴
chart.getDataAxis().setAxisMax(100);
chart.getDataAxis().setAxisMin(0);
chart.getDataAxis().setAxisSteps(5);
// 定义数据轴标签显示格式
chart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
Double tmp = Double.parseDouble(value);
DecimalFormat df = new DecimalFormat("#0");
String label = df.format(tmp).toString();
return (label);
}
});
// 在柱形顶部显示值
chart.getBar().setItemLabelVisible(true);
// 设定格式
chart.setItemLabelFormatter(new IFormatterDoubleCallBack() {
@Override
public String doubleFormatter(Double value) {
// TODO Auto-generated method stub
DecimalFormat df = new DecimalFormat("#0");
String label = df.format(value).toString();
return label;
}
});
// 让柱子间不留空白
chart.getBar().setBarInnerMargin(0f);
// 隐藏Key
chart.getPlotLegend().hide();
chart.disableHighPrecision();
} catch (Exception e) {
// TODO Auto-generated catch block
Log.e(TAG, e.toString());
}
}
use of org.xclcharts.common.IFormatterTextCallBack in project XCL-Charts by xcltapestry.
the class BarChart07View_left method chartRender.
private void chartRender() {
try {
// 标题
chart.setTitle("柱形图左右移动演示");
chart.addSubtitle("(XCL-Charts Demo)");
chart.setTitleAlign(XEnum.HorizontalAlign.LEFT);
// 数据源
chart.setDataSource(chartData);
chart.setCategories(chartLabels);
chart.setCustomLines(mCustomLineDataset);
// 图例
chart.getAxisTitle().setLeftTitle("参考成年男性标准值");
// 数据轴
chart.getDataAxis().setAxisMax(40);
chart.getDataAxis().setAxisMin(0);
chart.getDataAxis().setAxisSteps(5);
// 指隔多少个轴刻度(即细刻度)后为主刻度
chart.getDataAxis().setDetailModeSteps(2);
// 定义数据轴标签显示格式
chart.getDataAxis().setLabelFormatter(new IFormatterTextCallBack() {
@Override
public String textFormatter(String value) {
// TODO Auto-generated method stub
Double tmp = Double.parseDouble(value);
DecimalFormat df = new DecimalFormat("#0");
String label = df.format(tmp).toString();
return (label);
}
});
chart.getDataAxis().hideAxisLine();
// 隐藏Key
chart.getPlotLegend().hide();
chart.getCategoryAxis().hide();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations