1.效果图

2.xml代码

activity_column_chart.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
fragment_column_chart.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<lecho.lib.hellocharts.view.ColumnChartView
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</lecho.lib.hellocharts.view.ColumnChartView>
</RelativeLayout>

3.java代码

ColumnChartActivity.java
public class ColumnChartActivity extends AppCompatActivity {

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_column_chart);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
}
} /**
* A fragment containing a column chart.
*/
public static class PlaceholderFragment extends Fragment { private static final int DEFAULT_DATA = 0;
private static final int SUBCOLUMNS_DATA = 1;
private static final int STACKED_DATA = 2;
private static final int NEGATIVE_SUBCOLUMNS_DATA = 3;
private static final int NEGATIVE_STACKED_DATA = 4; private ColumnChartView chart;
private ColumnChartData data;
private boolean hasAxes = true;
private boolean hasAxesNames = true;
private boolean hasLabels = false;
private boolean hasLabelForSelected = false;
private int dataType = DEFAULT_DATA; public PlaceholderFragment() {
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.fragment_column_chart, container, false); chart = (ColumnChartView) rootView.findViewById(R.id.chart);
chart.setOnValueTouchListener(new ValueTouchListener()); generateData(); return rootView;
} private void generateDefaultData() {
int numSubcolumns = 1;
int numColumns = 8;
// Column can have many subcolumns, here by default I use 1 subcolumn in each of 8 columns.
List<Column> columns = new ArrayList<Column>();
List<SubcolumnValue> values;
for (int i = 0; i < numColumns; ++i) { values = new ArrayList<SubcolumnValue>();
for (int j = 0; j < numSubcolumns; ++j) {
values.add(new SubcolumnValue((float) Math.random() * 50f + 5, ChartUtils.pickColor()));
} Column column = new Column(values);
column.setHasLabels(hasLabels);
column.setHasLabelsOnlyForSelected(hasLabelForSelected);
columns.add(column);
} data = new ColumnChartData(columns); if (hasAxes) {
Axis axisX = new Axis();
Axis axisY = new Axis().setHasLines(true);
if (hasAxesNames) {
axisX.setName("Axis X");
axisY.setName("Axis Y");
}
data.setAxisXBottom(axisX);
data.setAxisYLeft(axisY);
} else {
data.setAxisXBottom(null);
data.setAxisYLeft(null);
} chart.setColumnChartData(data); } /**
* Generates columns with subcolumns, columns have larger separation than subcolumns.
*/
private void generateSubcolumnsData() {
int numSubcolumns = 4;
int numColumns = 4;
// Column can have many subcolumns, here I use 4 subcolumn in each of 8 columns.
List<Column> columns = new ArrayList<Column>();
List<SubcolumnValue> values;
for (int i = 0; i < numColumns; ++i) { values = new ArrayList<SubcolumnValue>();
for (int j = 0; j < numSubcolumns; ++j) {
values.add(new SubcolumnValue((float) Math.random() * 50f + 5, ChartUtils.pickColor()));
} Column column = new Column(values);
column.setHasLabels(hasLabels);
column.setHasLabelsOnlyForSelected(hasLabelForSelected);
columns.add(column);
} data = new ColumnChartData(columns); if (hasAxes) {
Axis axisX = new Axis();
Axis axisY = new Axis().setHasLines(true);
if (hasAxesNames) {
axisX.setName("Axis X");
axisY.setName("Axis Y");
}
data.setAxisXBottom(axisX);
data.setAxisYLeft(axisY);
} else {
data.setAxisXBottom(null);
data.setAxisYLeft(null);
} chart.setColumnChartData(data); } /**
* Generates columns with stacked subcolumns.
*/
private void generateStackedData() {
int numSubcolumns = 4;
int numColumns = 8;
// Column can have many stacked subcolumns, here I use 4 stacke subcolumn in each of 4 columns.
List<Column> columns = new ArrayList<Column>();
List<SubcolumnValue> values;
for (int i = 0; i < numColumns; ++i) { values = new ArrayList<SubcolumnValue>();
for (int j = 0; j < numSubcolumns; ++j) {
values.add(new SubcolumnValue((float) Math.random() * 20f + 5, ChartUtils.pickColor()));
} Column column = new Column(values);
column.setHasLabels(hasLabels);
column.setHasLabelsOnlyForSelected(hasLabelForSelected);
columns.add(column);
} data = new ColumnChartData(columns); // Set stacked flag.
data.setStacked(true); if (hasAxes) {
Axis axisX = new Axis();
Axis axisY = new Axis().setHasLines(true);
if (hasAxesNames) {
axisX.setName("Axis X");
axisY.setName("Axis Y");
}
data.setAxisXBottom(axisX);
data.setAxisYLeft(axisY);
} else {
data.setAxisXBottom(null); data.setAxisYLeft(null);
} chart.setColumnChartData(data);
} private void generateNegativeSubcolumnsData() { int numSubcolumns = 4;
int numColumns = 4;
List<Column> columns = new ArrayList<Column>();
List<SubcolumnValue> values;
for (int i = 0; i < numColumns; ++i) { values = new ArrayList<SubcolumnValue>();
for (int j = 0; j < numSubcolumns; ++j) {
int sign = getSign();
values.add(new SubcolumnValue((float) Math.random() * 50f * sign + 5 * sign, ChartUtils.pickColor
()));
} Column column = new Column(values);
column.setHasLabels(hasLabels);
column.setHasLabelsOnlyForSelected(hasLabelForSelected);
columns.add(column);
} data = new ColumnChartData(columns); if (hasAxes) {
Axis axisX = new Axis();
Axis axisY = new Axis().setHasLines(true);
if (hasAxesNames) {
axisX.setName("Axis X");
axisY.setName("Axis Y");
}
data.setAxisXBottom(axisX);
data.setAxisYLeft(axisY);
} else {
data.setAxisXBottom(null);
data.setAxisYLeft(null);
} chart.setColumnChartData(data);
} private void generateNegativeStackedData() { int numSubcolumns = 4;
int numColumns = 8;
// Column can have many stacked subcolumns, here I use 4 stacke subcolumn in each of 4 columns.
List<Column> columns = new ArrayList<Column>();
List<SubcolumnValue> values;
for (int i = 0; i < numColumns; ++i) { values = new ArrayList<SubcolumnValue>();
for (int j = 0; j < numSubcolumns; ++j) {
int sign = getSign();
values.add(new SubcolumnValue((float) Math.random() * 20f * sign + 5 * sign, ChartUtils.pickColor()));
} Column column = new Column(values);
column.setHasLabels(hasLabels);
column.setHasLabelsOnlyForSelected(hasLabelForSelected);
columns.add(column);
} data = new ColumnChartData(columns); // Set stacked flag.
data.setStacked(true); if (hasAxes) {
Axis axisX = new Axis();
Axis axisY = new Axis().setHasLines(true);
if (hasAxesNames) {
axisX.setName("Axis X");
axisY.setName("Axis Y");
}
data.setAxisXBottom(axisX);
data.setAxisYLeft(axisY);
} else {
data.setAxisXBottom(null);
data.setAxisYLeft(null);
} chart.setColumnChartData(data);
} private int getSign() {
int[] sign = new int[]{-1, 1};
return sign[Math.round((float) Math.random())];
} private void generateData() {
switch (dataType) {
case DEFAULT_DATA:
generateDefaultData();
break;
case SUBCOLUMNS_DATA:
generateSubcolumnsData();
break;
case STACKED_DATA:
generateStackedData();
break;
case NEGATIVE_SUBCOLUMNS_DATA:
generateNegativeSubcolumnsData();
break;
case NEGATIVE_STACKED_DATA:
generateNegativeStackedData();
break;
default:
generateDefaultData();
break;
}
} private class ValueTouchListener implements ColumnChartOnValueSelectListener { @Override
public void onValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
Toast.makeText(getActivity(), "Selected: " + value, Toast.LENGTH_SHORT).show();
} @Override
public void onValueDeselected() {
// TODO Auto-generated method stub } } } }

图表框架HelloCharts(2)柱状图的更多相关文章

  1. 图表框架HelloCharts(3)饼状图

    1 效果图 2 xml文件 activity_pie_chart.xml <FrameLayout xmlns:android="http://schemas.android.com/ ...

  2. 图表框架HelloCharts(1)线形图

    效果图 1. 导入 .aar 2. fragment_line_chart.xml <RelativeLayout xmlns:android="http://schemas.andr ...

  3. 手把手教你实现折线图之------安卓最好用的图表库hellocharts之最详细的使用介绍

    因为项目需要搞一个折线图,按照日期显示相应的成绩,所以有了本文. 以前用过一次XCL-chart,但是感觉只适合固定图表,不去滑动的那种,因为你一滑动太卡了你懂得(毕竟作者好久没更新优化了),拙言大神 ...

  4. 9 个基于JavaScript 和 CSS 的 Web 图表框架

    COMSHARP CMS 写道:jQuery, MooTools, Prototype 等优秀的 JavaScript 框架拥有各种强大的功能,包括绘制 Web图表,使用这些框架以及相应插件,我们可以 ...

  5. Android图表库hellocharts详解

    感谢大佬:https://www.cnblogs.com/huolongluo/p/5988644.html 因为项目需要搞一个折线图,按照日期显示相应的成绩,所以有了本文. 以前用过一次XCL-ch ...

  6. &#128200;&#128200;&#128200;&#128200;&#128200;iOS 图表框架 AAChartKit ---强大的高颜值数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图

    English Document

  7. 使用HelloCharts绘制柱状图

    首先下载依赖库 ,有现成的jar包:hellocharts-library-1.5.8.jar 在需要的布局中直接使用: <lecho.lib.hellocharts.view.ColumnCh ...

  8. OSChina技术导向:Java图表框架JFreeChart

    JFreeChart主要用来各种各样的图表,这些图表包括:饼图.柱状图(普通柱状图以及堆栈柱状图).线图.区域图.分布图.混合图.甘特图以及一些仪表盘等等.             JavaDoc文档 ...

  9. Python图表数据可视化Seaborn:2. 分类数据可视化-分类散点图|分布图(箱型图|小提琴图|LV图表)|统计图(柱状图|折线图)

    1. 分类数据可视化 - 分类散点图 stripplot( ) / swarmplot( ) sns.stripplot(x="day",y="total_bill&qu ...

随机推荐

  1. CentOS下安装使用start-stop-daemon

    CentOS下安装使用start-stop-daemon 在centos下下了个自启动的服务器脚本 执行的时候发现找不到start-stop-daemon命令 好吧 执行手动编译一下 加上这个命令 w ...

  2. JSONP实现跨域

    首先提出:什么是跨域?如何解决跨域? 跨域可以简单的理解为从一个域名访问另一个域名,由于javascript的同源政策的限制,出于安全的考虑,不允许浏览器这么做.比如a.com 域名下的js无法操作b ...

  3. 不同版本strtotime(&quot;2016-09-04&quot;)输出不同问题

    在php版本改变后,突然发现查询没结果.然后发现是时间不同了,测试以后发现以前版本的php和现在版本的phpstrtotime输出不同.原来是时区配置问题,解决办法:http://zhidao.bai ...

  4. Nginx下Redmine2.6配置

    Apache下Redmine2.6配置,请参考:http://blog.linuxeye.com/405.html CentOS6.6下安装Redmine2.6+MySQL5.6+Nginx,教程如下 ...

  5. SXT分布式缓存技术公开课的观后感

    最近几天在研究Redis,Redis作为最近比较流行的缓存技术,其特点还是很明显的,Redis使用Key-Value的结构来存储数据,Redis也是内存型的数据库,数据一开始是保存在内存中的,通过某些 ...

  6. 我的天哪,现在的移动VIN码识别已经这么。。

    VIN码是英文(Vehicle Identification Number)的缩写,译为车辆识别代码,又称车辆识别码,车辆识别代码,车辆识别号,车辆识别代号,VIN码是表明车辆身份的代码.VIN码由1 ...

  7. 201521123013 《Java程序设计》第9周学习总结

    1. 本章学习总结 2. 书面作业 Q1.常用异常题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免? 经常出现Class ...

  8. ArcGIS API for Javascript 加载天地图(经纬度投影)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. HTML 文本内容居中

    简单描述:使用bootstrap 的model弹出框,里边的标题内容是靠左的,想把内容居中. 操作:给标题的class加上"text-center". 另外 我发现,在使用mode ...

  10. SQL SERVER-查询爆破sa密码的主机

    drop table if exists #sql create table #sql ( Logdatae ), processinfo ), [text] varchar(max) ) go IN ...