package com.xxmassdeveloper.mpchartexample.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.xxmassdeveloper.mpchartexample.R;
import java.util.List;
/**
* @Info
* @Auth Bello
* @Time 18-3-7 下午3:27
* @Ver
*/
public class MyHorizontalChart extends RelativeLayout {
private Context context;
private TextView titleText;
private CheckBox showBtn;
//组合图形控件
private HorizontalChartView mChart;
public MyHorizontalChart(Context context) {
super(context);
initView(context);
}
public MyHorizontalChart(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
/**
* 加载UI布局
* @param context
*/
private void initView(Context context){
this.context = context;
View.inflate(context, R.layout.lt_my_horizontal, this);
showBtn = this.findViewById(R.id.chart_show_text);
showBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
mChart.setVisibleValue(!mChart.isVisibleValue());
mChart.invalidate();
}
});
mChart = this.findViewById(R.id.chart_horizontal);
}
/**
* 设置统计项目列表
*
* @param legend1
* @param legend2
* @param chartName
* @param barList
*/
public void setBarList(String chartName, String legend1, String legend2, String unit1, String unit2, List<HorizontalChartView.Bar>
barList) {
mChart.setBarList(chartName, legend1, legend2, unit1, unit2, barList);
}
}