use of org.xclcharts.common.IFormatterDoubleCallBack in project XCL-Charts by xcltapestry.
the class MultiAxisChart01View method renderBar.
/**
* 定制柱形顶上的标签格式
*/
private void renderBar() {
Bar bar = chart.getBar();
bar.setItemLabelVisible(true);
bar.setItemLabelRotateAngle(-90);
bar.getItemLabelPaint().setFakeBoldText(true);
chart.setItemLabelFormatter(new IFormatterDoubleCallBack() {
@Override
public String doubleFormatter(Double value) {
// TODO Auto-generated method stub
// DecimalFormat df=new DecimalFormat("#0.00");
DecimalFormat df = new DecimalFormat("#0");
return df.format(value).toString();
}
});
}
use of org.xclcharts.common.IFormatterDoubleCallBack 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.IFormatterDoubleCallBack 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.IFormatterDoubleCallBack in project XCL-Charts by xcltapestry.
the class BarChart11View method chartRender.
private void chartRender() {
try {
// 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
int[] ltrb = getBarLnDefaultSpadding();
chart.setPadding(ltrb[0] + DensityUtil.dip2px(this.getContext(), 40), ltrb[1] + DensityUtil.dip2px(this.getContext(), 10), ltrb[2], ltrb[3]);
// 标题
chart.setTitle("Cloud Computing Services\n(SOHO/SMB) - Overall Scores");
// chart.addSubtitle("(XCL-Charts Demo)");
chart.setTitleAlign(XEnum.HorizontalAlign.CENTER);
// 数据源
chart.setDataSource(chartData);
chart.setCategories(chartLabels);
// 数据轴
chart.getDataAxis().setAxisMax(8);
chart.getDataAxis().setAxisMin(6);
chart.getDataAxis().setAxisSteps(1);
chart.getDataAxis().hideAxisLine();
chart.getDataAxis().hideTickMarks();
chart.getCategoryAxis().hideTickMarks();
chart.getDataAxis().setVerticalTickPosition(XEnum.VerticalAlign.TOP);
chart.getCategoryAxis().setVerticalTickPosition(XEnum.VerticalAlign.TOP);
chart.setChartDirection(XEnum.Direction.HORIZONTAL);
chart.setDataAxisLocation(XEnum.AxisLocation.TOP);
// 定义数据轴标签显示格式
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.0");
String label = df.format(tmp).toString();
return (label);
}
});
// 设定格式
chart.setItemLabelFormatter(new IFormatterDoubleCallBack() {
@Override
public String doubleFormatter(Double value) {
// TODO Auto-generated method stub
DecimalFormat df = new DecimalFormat("#0.0");
String label = df.format(value).toString();
return label;
}
});
// 隐藏Key
chart.getPlotLegend().hide();
// 提高性能
chart.disableHighPrecision();
chart.setApplyBackgroundColor(true);
chart.setBackgroundColor(Color.BLACK);
chart.getDataAxis().getTickLabelPaint().setColor(Color.WHITE);
chart.getCategoryAxis().getTickLabelPaint().setColor(Color.WHITE);
chart.getPlotTitle().getTitlePaint().setColor(Color.WHITE);
chart.getPlotTitle().getSubtitlePaint().setColor(Color.WHITE);
chart.getBar().getItemLabelPaint().setColor(Color.WHITE);
chart.getPlotGrid().getVerticalLinePaint().setColor(Color.rgb(106, 194, 57));
chart.getPlotGrid().getHorizontalLinePaint().setColor(Color.rgb(106, 194, 57));
// chart.getPlotGrid().showHorizontalLines();
chart.getPlotGrid().showVerticalLines();
chart.getBar().setBarStyle(XEnum.BarStyle.FILL);
chart.getBar().setItemLabelVisible(true);
chart.getBar().getItemLabelPaint().setTextSize(22);
chart.getBar().setItemLabelStyle(XEnum.ItemLabelStyle.INNER);
chart.getCategoryAxis().getAxisPaint().setColor(Color.rgb(106, 194, 57));
chart.getDataAxis().setVerticalTickPosition(XEnum.VerticalAlign.TOP);
chart.ActiveListenItemClick();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.xclcharts.common.IFormatterDoubleCallBack in project XCL-Charts by xcltapestry.
the class AreaChart02View method chartRender.
private void chartRender() {
try {
// 设置绘图区默认缩进px值,留置空间显示Axis,Axistitle....
int[] ltrb = getBarLnDefaultSpadding();
chart.setPadding(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
// 轴数据源
// 标签轴
chart.setCategories(mLabels);
// 数据轴
chart.setDataSource(mDataset);
// 仅横向平移
chart.setPlotPanMode(XEnum.PanMode.HORIZONTAL);
// 数据轴最大值
chart.getDataAxis().setAxisMax(100);
// 数据轴刻度间隔
chart.getDataAxis().setAxisSteps(10);
// 网格
chart.getPlotGrid().showHorizontalLines();
chart.getPlotGrid().showVerticalLines();
// 把顶轴和右轴隐藏
// chart.hideTopAxis();
// chart.hideRightAxis();
// 把轴线和刻度线给隐藏起来
chart.getDataAxis().hideAxisLine();
chart.getDataAxis().hideTickMarks();
chart.getCategoryAxis().hideAxisLine();
chart.getCategoryAxis().hideTickMarks();
// 标题
chart.setTitle("平滑区域图");
chart.addSubtitle("(XCL-Charts Demo)");
// 轴标题
chart.getAxisTitle().setLowerTitle("(年份)");
// 透明度
chart.setAreaAlpha(180);
// 显示图例
chart.getPlotLegend().show();
// 激活点击监听
chart.ActiveListenItemClick();
// 为了让触发更灵敏,可以扩大5px的点击监听范围
chart.extPointClickRange(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.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.getPlotArea().extWidth(100f);
// chart.disablePanMode(); //test
CustomLineData line1 = new CustomLineData("标识线", 60d, Color.RED, 7);
line1.setCustomLineCap(XEnum.DotStyle.CROSS);
line1.setLabelHorizontalPostion(Align.CENTER);
line1.setLabelOffset(15);
line1.getLineLabelPaint().setColor(Color.RED);
mCustomLineDataset.add(line1);
chart.setCustomLines(mCustomLineDataset);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(TAG, e.toString());
}
}
Aggregations