您好,登錄后才能下訂單哦!
import java.util.ArrayList;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.animation.AnimationUtils;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.XLabels;
import com.github.mikephil.charting.utils.XLabels.XLabelPosition;
public class MainActivity extends ActionBarActivity {
private BarChart mSaltChart;
public void v){
startActivity(new Intent(this,MainActivity.class));
finish();
overridePendingTransition(0, 0);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSaltChart = (BarChart) findViewById(R.id.chart_salt);
initChart();
initAnimotion();
}
private void initAnimotion() {
mSaltChart.setAnimation(AnimationUtils.loadAnimation(this,
R.anim.in_leftright));
mSaltChart.setVisibility(View.VISIBLE);
mSaltChart.animateY(1000);
}
private void initChart() {
// TODO Auto-generated method stub
/**
* 單位
*/
mSaltChart.setUnit("ml");
/**
* 橫坐標
*/
mSaltChart.setDescription("鹽量監控 ml/h");
/**
* 柱狀圖數量
*/
mSaltChart.setMaxVisibleValueCount(12);
/**
* 設置圖表中的值的位數
*/
mSaltChart.setValueDigits(2);
/**
* 3D效果
*/
mSaltChart.set3DEnabled(true);
/**
* 縮放只能在X和Y軸分別做
*/
mSaltChart.setPinchZoom(false);
mSaltChart.setDrawBarShadow(false);
mSaltChart.setDrawVerticalGrid(false);
mSaltChart.setDrawHorizontalGrid(false);
mSaltChart.setDrawGridBackground(false);
XLabels xLabels = mSaltChart.getXLabels();
xLabels.setPosition(XLabelPosition.BOTTOM);
xLabels.setCenterXLabelText(true);
xLabels.setSpaceBetweenLabels(0);
mSaltChart.setDrawYLabels(true);
mSaltChart.setDrawLegend(false);
mSaltChart.setDrawYValues(true);
/**
* 設置動畫時間
*/
mSaltChart.animateY(1000);
/**
* 柱狀圖數據傳入
*/
new chartTask().execute(50);
}
/**
* 柱狀圖數據傳入
*/
private class chartTask extends AsyncTask<Integer, Integer, BarData> {
@Override
protected void onPreExecute() {
}
@Override
protected BarData doInBackground(Integer... arg0) {
// TODO Auto-generated method stub
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < 12; i++) {
float mult = (30 + 1);
float val1 = (float) (Math.random() * mult) + mult / 3;
yVals1.add(new BarEntry((int) val1, i));
}
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < 12; i++) {
xVals.add(i * 2 + "h");
}
/**
* 設置顏色
*/
BarDataSet set1 = new BarDataSet(yVals1, "Data Set");
set1.setColors(ColorTemplate.createColors(MainActivity.this,
ColorTemplate.VORDIPLOM_COLORS));
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);
return data;
}
@Override
protected void onPostExecute(BarData result) {
// TODO Auto-generated method stub
mSaltChart.setData(result);
mSaltChart.invalidate();
super.onPostExecute(result);
}
}
}
需要的朋友請私聊,因為還有一個架包沒法上傳(702246917)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。