您的位置:首页 > 其它

自己绘制的可点击,可滑动,可动态添加的柱状图

2016-06-07 16:41 477 查看
一,xml文件布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- 第一个表的标题栏 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="90dp">

<TextView
android:id="@+id/tv_no"
android:layout_width="55dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:gravity="center"
android:text="已检查"
android:textSize="14sp" />

<TextView
android:layout_width="35dp"
android:layout_height="12dp"
android:layout_alignBottom="@id/tv_no"
android:layout_gravity="center"
android:background="#61A0A8"
android:gravity="center" />
</LinearLayout>

<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="20dp">

<TextView
android:layout_width="55dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:gravity="center"
android:text="未检查"
android:textSize="14sp" />

<TextView
android:layout_width="35dp"
android:layout_height="12dp"
android:layout_alignBottom="@id/tv_no"
android:layout_gravity="center"
android:background="#D4A156"
android:gravity="center" />
</LinearLayout>
</LinearLayout>

<!-- 第一个表街道标签及柱状图展示 -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="200dp">

<LinearLayout
android:id="@+id/barCharts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>

</ScrollView>

<!-- 第一个表的X轴标签及刻度 -->
<LinearLayout
androi
20000
d:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:background="#00000000"
android:enabled="true"
android:text="企业数"
android:textColor="#333333"
android:textSize="14sp" />
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="7"
android:layout_height="wrap_content">
<View
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentTop="true"
android:layout_marginRight="8dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="50dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="100dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="150dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="200dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="250dp"
android:background="#CCCCCC" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="0"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_marginTop="12dp"
android:text="100"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="85dp"
android:layout_marginTop="12dp"
android:text="200"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="12dp"
android:text="300"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="185dp"
android:layout_marginTop="12dp"
android:text="400"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="235dp"
android:layout_marginTop="12dp"
android:text="500"
android:textColor="#333333"
android:textSize="14sp" />
</RelativeLayout>
</LinearLayout>

<!-- 第二个表的标题栏 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="90dp">
<TextView
android:layout_width="55dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:gravity="center"
android:text="已整改"
android:textSize="14sp" />
<TextView
android:layout_width="35dp"
android:layout_height="12dp"
android:layout_gravity="center"
android:background="#91B3AE"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="20dp">

<TextView
android:layout_width="55dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:gravity="center"
android:text="未整改"
android:textSize="14sp" />

<TextView
android:layout_width="35dp"
android:layout_height="12dp"
android:layout_gravity="center"
android:background="#D48265"
android:gravity="center" />
</LinearLayout>

</LinearLayout>

<!-- 第二个表街道标签及柱状图展示 -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="200dp">
<LinearLayout
android:id="@+id/barCharts2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>

<!-- 第二个表的X轴标签及刻度 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:background="#00000000"
android:enabled="false"
android:text="企业数"
android:textColor="#333333"
android:textSize="14sp" />
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="7"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentTop="true"
android:layout_marginRight="8dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="50dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="100dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="150dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="200dp"
android:background="#CCCCCC" />
<View
android:layout_width="1dp"
android:layout_height="4dp"
android:layout_marginLeft="250dp"
android:background="#CCCCCC" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="0"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_marginTop="12dp"
android:text="100"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="85dp"
android:layout_marginTop="12dp"
android:text="200"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="12dp"
android:text="300"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="185dp"
android:layout_marginTop="12dp"
android:text="400"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="235dp"
android:layout_marginTop="12dp"
android:text="500"
android:textColor="#333333"
android:textSize="14sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>


二,layout_street_barchartitem.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/barChartitem">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/itemLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#00000000"
android:text="龙城街道"
android:textColor="#333333"
android:textSize="14sp" />

<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#CCCCCC"></View>

<LinearLayout
android:id="@+id/itemData"
android:layout_width="0dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_weight="7">
<View
android:id="@+id/V1"
android:layout_width="150dp"
android:layout_height="12dp"
android:layout_gravity="center_vertical"
android:background="#61A0A8"></View>

<View
android:id="@+id/V2"
android:layout_width="100dp"
android:layout_height="12dp"
android:layout_gravity="center_vertical"
android:background="#D4A156"></View>
</LinearLayout>

</LinearLayout>
</LinearLayout>


三,Activity

package com.zdst_03.app_bart;

import android.app.Activity;
import android.app.Service;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StreetLabelActivity extends Activity {

private LinearLayout barCharts;
private LinearLayout barCharts2;
private LinearLayout itemData;
private List<LinearLayout> listData;

private List<Map<String, String>> barDatas;
private List<TextView> labels;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_street);
//初始化
initView();
//创建动态添加街道标签的方法
initData();
}

//初始化View
void initView() {
barCharts = (LinearLayout) this.findViewById(R.id.barCharts);
itemData = (LinearLayout) this.findViewById(R.id.itemData);
listData = new ArrayList<>();
barCharts2 = (LinearLayout) this.findViewById(R.id.barCharts2);
}

void initData() {
labels = new ArrayList<>();
barDatas = new ArrayList<>();
Map<String, String> map = new HashMap<>();
map.put("BarLabelName", "龙城街道");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "龙岗街道");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "坪地街道");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "横岗街道");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "平湖街道");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "南湾街道");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "布吉街道");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "坂田街道");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
barCharts.removeAllViews();
createBar(barDatas, "检查类型");
barCharts2.removeAllViews();
createBar(barDatas, "整改类型");
}

//    String []streetName={"龙城街道","龙岗街道","坪地街道","横岗街道","平湖街道","南湾街道","布吉街道","坂田街道"};
//
//    String[] community1 = new String[]{"龙西社区", "尚景社区", "五联社区", "新联社区", "吉祥社区",
//            "嶂背社区", "爱联社区", "紫薇社区", "盛平社区", "愉园社区", "黄阁坑社区", "回龙埔社区",
//            "龙红格社区"};
//
//    String[] community2 = new String[]{"龙东社区", "龙新社区", "平南社区", "南约社区", "同乐社区",
//            "新生社区", "龙岗社区", "南联社区", "宝龙社区", "龙岗墟社区", "同心社区", "同德社区"};
//
//    String[] community3 = new String[]{"怡心社区", "坪东社区", "中心社区", "坪西社区", "高桥社区",
//            "坪地社区", "年丰社区", "六联社区", "四方埔社区"};
//
//    String[] community4 = new String[]{"西坑社区", "银荷社区", "松柏社区", "怡锦社区", "大康社区",
//            "四联社区", "志盛社区", "安良社区", "荷坳社区", "六约社区", "红棉社区", "保安社区",
//            "华乐社区", "横岗社区", "华侨新村社区"};
//
//    String[] community5 = new String[]{"新南社区", "力昌社区", "新木社区", "平湖社区", "禾花社区",
//            "山厦社区", "凤凰社区", "良安田社区", "鹅公岭社区", "辅城坳社区", "上木古社区",
//            "白坭坑社区"};
//
//    String[] community6 = new String[]{"宝岭社区", "丹平社区", "厦村社区", "南新社区", "吉厦社区",
//            "康乐社区", "南龙社区", "沙湾社区", "沙塘布社区", "上李朗社区", "下李朗社区",
//            "樟树布社区", "南岭村社区", "丹竹头社区"};
//
//
//    String[] community7 = new String[]{"长龙社区", "凤凰社区", "光华社区", "国展社区", "龙岭社区",
//            "茂业社区", "文景社区", "金排社区", "可园社区", "翠湖社区", "龙珠社区",
//            "大芬社区", "德兴社区", "罗岗社区", "南三社区", "丽湖社区", "布吉社区", "布吉圩社区",
//            "水径社区", "木棉湾社区", "甘坑社区", "三联社区", "中海怡翠社区", "东方半岛社区"};
//
//    String[] community8 = new String[]{"南坑社区", "马安堂社区", "岗头社区", "杨美社区", "新雪社区",
//            "大发埔社区", "象角塘社区", "坂田社区", "五和社区", "第五园社区", "四季花城社区",
//            "万科城社区"};

/**
* 动态添加数据
*
* @param datas
* @param type
*/
void createBar(List<Map<String, String>> datas, String type) {

switch (type) {
case "整改类型":

if (datas.size() < 5) {
for (int i = 0; i < datas.size(); i++) {
LinearLayout item1 = (LinearLayout) ((LayoutInflater) this.getSystemService(Service.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_street_barchartitem, null);
//添加标签
TextView Label = ((TextView) item1.findViewById(R.id.itemLabel));
Label.setText(datas.get(i).get("BarLabelName"));
//第一个柱子
View data1 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V1);
//第一个柱子设置参数
data1.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar1_data")), 25));
//第二个柱子
View data2 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V2);
//第二个柱子设置参数
data2.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar2_data")), 25));
//                        listData.add(item1);
barCharts2.addView(item1);
labels.add(Label);

Label.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (((TextView) v).getText().toString()) {
case "龙城街道":

break;
case "":
break;
}
}
});
}
for (int i = 0; i < 5 - datas.size(); i++) {
LinearLayout item1 = (LinearLayout) ((LayoutInflater) this.getSystemService(Service.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_street_barchartitem, null);
//添加标签
TextView Label = ((TextView) item1.findViewById(R.id.itemLabel));
//                        Label.setText(datas.get(i).get("BarLabelName"));
Label.setVisibility(View.INVISIBLE);
//第一个柱子
View data1 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V1);
data1.setVisibility(View.INVISIBLE);
//                        //第一个柱子设置参数
//                        data1.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar1_data")), 25));
//第二个柱子
View data2 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V2);
data2.setVisibility(View.INVISIBLE);
//                        //第二个柱子设置参数
//                        data2.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar2_data")),25));
//                        listData.add(item1);
barCharts2.addView(item1);
}
} else {
for (int i = 0; i < datas.size(); i++) {
LinearLayout item1 = (LinearLayout) ((LayoutInflater) this.getSystemService(Service.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_street_barchartitem, null);
//添加标签
TextView Label = ((TextView) item1.findViewById(R.id.itemLabel));
Label.setText(datas.get(i).get("BarLabelName"));
//第一个柱子
View data1 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V1);
//第一个柱子设置参数
data1.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar1_data")), 25));
//第二个柱子
View data2 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V2);
//第二个柱子设置参数
data2.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar2_data")), 25));
//                        listData.add(item1);
barCharts2.addView(item1);
labels.add(Label);
Label.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

switch (((TextView) v).getText().toString()) {
case "龙城街道":

barCharts2.removeAllViews();
barDatas.clear();
Map<String, String> map = new HashMap<>();
map.put("BarLabelName", "龙西社区");
map.put("Bar1_data", "50");
map.put("Bar2_data", "80");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "尚景社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "120");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "五联社区");
map.put("Bar1_data", "90");
map.put("Bar2_data", "30");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "新联社区");
map.put("Bar1_data", "40");
map.put("Bar2_data", "90");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "吉祥社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "嶂背社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "爱联社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "紫薇社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "盛平社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "愉园社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "黄阁坑社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "回龙埔社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "龙红格社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
barCharts2.removeAllViews();
createBar(barDatas, "整改类型");
break;
case "":
break;
}
}
});
}
}
break;

case "检查类型":
if (datas.size() < 5) {
for (int i = 0; i < datas.size(); i++) {
LinearLayout item1 = (LinearLayout) ((LayoutInflater) this.getSystemService(Service.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_street_barchartitem, null);
//添加标签
TextView Label = ((TextView) item1.findViewById(R.id.itemLabel));
Label.setText(datas.get(i).get("BarLabelName"));
//第一个柱子
View data1 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V1);
//第一个柱子设置参数
data1.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar1_data")), 25));
//第二个柱子
View data2 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V2);
//第二个柱子设置参数
data2.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar2_data")), 25));
//                        listData.add(item1);
barCharts.addView(item1);
labels.add(Label);

Label.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (((TextView) v).getText().toString()) {
case "龙城街道":

break;
case "":
break;
}
}
});
}
for (int i = 0; i < 5 - datas.size(); i++) {
LinearLayout item1 = (LinearLayout) ((LayoutInflater) this.getSystemService(Service.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_street_barchartitem, null);
//添加标签
TextView Label = ((TextView) item1.findViewById(R.id.itemLabel));
//                        Label.setText(datas.get(i).get("BarLabelName"));
Label.setVisibility(View.INVISIBLE);
//第一个柱子
View data1 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V1);
data1.setVisibility(View.INVISIBLE);
//                        //第一个柱子设置参数
//                        data1.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar1_data")), 25));
//第二个柱子
View data2 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V2);
data2.setVisibility(View.INVISIBLE);
//                        //第二个柱子设置参数
//                        data2.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar2_data")),25));
//                        listData.add(item1);
barCharts.addView(item1);
}
} else {
for (int i = 0; i < datas.size(); i++) {
LinearLayout item1 = (LinearLayout) ((LayoutInflater) this.getSystemService(Service.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_street_barchartitem, null);
//添加标签
TextView Label = ((TextView) item1.findViewById(R.id.itemLabel));
Label.setText(datas.get(i).get("BarLabelName"));
//第一个柱子
View data1 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V1);
//第一个柱子设置参数
data1.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar1_data")), 25));
//第二个柱子
View data2 = ((View) item1.findViewById(R.id.itemData)).findViewById(R.id.V2);
//第二个柱子设置参数
data2.setLayoutParams(new LinearLayout.LayoutParams(Integer.parseInt(datas.get(i).get("Bar2_data")), 25));
//                        listData.add(item1);
barCharts.addView(item1);
labels.add(Label);
Label.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

switch (((TextView) v).getText().toString()) {
case "龙城街道":

barCharts.removeAllViews();
barDatas.clear();
Map<String, String> map = new HashMap<>();
map.put("BarLabelName", "龙西社区");
map.put("Bar1_data", "50");
map.put("Bar2_data", "80");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "尚景社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "120");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "五联社区");
map.put("Bar1_data", "90");
map.put("Bar2_data", "30");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "新联社区");
map.put("Bar1_data", "40");
map.put("Bar2_data", "90");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "吉祥社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "嶂背社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "爱联社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "紫薇社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "盛平社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "愉园社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "黄阁坑社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "回龙埔社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
map = new HashMap<>();
map.put("BarLabelName", "龙红格社区");
map.put("Bar1_data", "100");
map.put("Bar2_data", "200");
barDatas.add(map);
createBar(barDatas, "检查类型");
break;
case "":
break;

9478
}
}
});
}
}
break;
default:
break;
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息