Search in sources :

Example 1 with ArcPosition

use of org.xclcharts.event.click.ArcPosition in project XCL-Charts by xcltapestry.

the class DountChart01View method triggerClick.

// 触发监听
private void triggerClick(float x, float y) {
    if (!chart.getListenItemClickStatus())
        return;
    ArcPosition record = chart.getPositionRecord(x, y);
    if (null == record)
        return;
    PieData pData = lPieData.get(record.getDataID());
    boolean isInvaldate = true;
    for (int i = 0; i < lPieData.size(); i++) {
        PieData cData = lPieData.get(i);
        if (i == record.getDataID()) {
            if (cData.getSelected()) {
                isInvaldate = false;
                break;
            } else {
                cData.setSelected(true);
            }
        } else
            cData.setSelected(false);
    }
    if (isInvaldate)
        this.invalidate();
}
Also used : ArcPosition(org.xclcharts.event.click.ArcPosition) PieData(org.xclcharts.chart.PieData) Paint(android.graphics.Paint)

Example 2 with ArcPosition

use of org.xclcharts.event.click.ArcPosition in project XCL-Charts by xcltapestry.

the class PieChart01View method triggerClick.

// 触发监听
private void triggerClick(float x, float y) {
    if (!chart.getListenItemClickStatus())
        return;
    ArcPosition record = chart.getPositionRecord(x, y);
    if (null == record)
        return;
    /*
		PieData pData = chartData.get(record.getDataID());		
		Toast.makeText(this.getContext(),								
				" key:" +  pData.getKey() +
				" Label:" + pData.getLabel() ,
				Toast.LENGTH_SHORT).show(); 
		*/
    // 用于处理点击时弹开,再点时弹回的效果
    PieData pData = chartData.get(record.getDataID());
    if (record.getDataID() == mSelectedID) {
        boolean bStatus = chartData.get(mSelectedID).getSelected();
        chartData.get(mSelectedID).setSelected(!bStatus);
    } else {
        if (mSelectedID >= 0)
            chartData.get(mSelectedID).setSelected(false);
        pData.setSelected(true);
    }
    mSelectedID = record.getDataID();
    this.refreshChart();
/*
		boolean isInvaldate = true;		
		for(int i=0;i < chartData.size();i++)
		{	
			PieData cData = chartData.get(i);
			if(i == record.getDataID())
			{
				if(cData.getSelected()) 
				{
					isInvaldate = false;
					break;
				}else{
					cData.setSelected(true);	
				}
			}else
				cData.setSelected(false);			
		}
		if(isInvaldate)this.invalidate();
		*/
}
Also used : ArcPosition(org.xclcharts.event.click.ArcPosition) PieData(org.xclcharts.chart.PieData)

Example 3 with ArcPosition

use of org.xclcharts.event.click.ArcPosition in project XCL-Charts by xcltapestry.

the class ClickChartsActivity method initActivity.

private void initActivity() {
    // 完全动态创建,无须XML文件.
    FrameLayout content = new FrameLayout(this);
    // 缩放控件放置在FrameLayout的上层,用于放大缩小图表
    FrameLayout.LayoutParams frameParm = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    frameParm.gravity = Gravity.BOTTOM | Gravity.RIGHT;
    // 图表显示范围在占屏幕大小的90%的区域内
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int scrWidth = (int) (dm.widthPixels * 0.9);
    int scrHeight = (int) (dm.heightPixels * 0.9);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(scrWidth, scrHeight);
    // 居中显示
    layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    // 图表view放入布局中,也可直接将图表view放入Activity对应的xml文件中
    final RelativeLayout chartLayout = new RelativeLayout(this);
    chartLayout.addView(mCharts, layoutParams);
    // 增加控件
    ((ViewGroup) content).addView(chartLayout);
    setContentView(content);
    mCharts.setOnPlotClickListener(new ChartArcListener() {

        // 可改成pointF,positionRecord,既当前点击点及位置记录
        @Override
        public void onClick(PointF point, ArcPosition positionRecord) {
            if (null == positionRecord)
                return;
            /**
             * 附注,如果数据源是从Activity传给view的,
             * 则可在此通过 positionRecord.getDataID() 得到对应的id来取相关信息。
             * 同理,其它图形也可依此形式来做,
             * 	如onClick的参数ArcPosition依图形类别,
             * 		可替换对应的PointPosition或BarPosition类
             */
            Toast.makeText(ClickChartsActivity.this, "[此处为Activity返回的信息] ID:" + positionRecord.getDataID(), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : ArcPosition(org.xclcharts.event.click.ArcPosition) LayoutParams(android.view.ViewGroup.LayoutParams) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) PointF(android.graphics.PointF) RelativeLayout(android.widget.RelativeLayout) DisplayMetrics(android.util.DisplayMetrics) ChartArcListener(org.xclcharts.event.click.ChartArcListener)

Example 4 with ArcPosition

use of org.xclcharts.event.click.ArcPosition in project XCL-Charts by xcltapestry.

the class PieChart02View method triggerClick.

// 触发监听
private void triggerClick(float x, float y) {
    if (!chart.getListenItemClickStatus())
        return;
    ArcPosition record = chart.getPositionRecord(x, y);
    if (null == record)
        return;
    PieData pData = chartData.get(record.getDataID());
    // boolean isInvaldate = true;
    for (int i = 0; i < chartData.size(); i++) {
        PieData cData = chartData.get(i);
        if (i == record.getDataID()) {
            if (cData.getSelected()) {
                // isInvaldate = false;
                break;
            } else {
                cData.setSelected(true);
            }
        } else
            cData.setSelected(false);
    }
    // 显示选中框
    chart.showFocusArc(record, pData.getSelected());
    chart.getFocusPaint().setStyle(Style.STROKE);
    chart.getFocusPaint().setStrokeWidth(5);
    chart.getFocusPaint().setColor(Color.GREEN);
    chart.getFocusPaint().setAlpha(100);
    // 在点击处显示tooltip
    mPaintToolTip.setColor(Color.RED);
    chart.getToolTip().setCurrentXY(x, y);
    chart.getToolTip().addToolTip(" key:" + pData.getKey() + " Label:" + pData.getLabel(), mPaintToolTip);
    this.refreshChart();
}
Also used : ArcPosition(org.xclcharts.event.click.ArcPosition) PieData(org.xclcharts.chart.PieData) Paint(android.graphics.Paint)

Example 5 with ArcPosition

use of org.xclcharts.event.click.ArcPosition in project XCL-Charts by xcltapestry.

the class PieChart3D01View method triggerClick.

// 触发监听
private void triggerClick(float x, float y) {
    ArcPosition record = chart.getPositionRecord(x, y);
    if (null == record)
        return;
    PieData pData = chartData.get(record.getDataID());
    Toast.makeText(this.getContext(), " key:" + pData.getKey() + " Label:" + pData.getLabel(), Toast.LENGTH_SHORT).show();
/*
		//在点击处显示tooltip
		mPaintToolTip.setColor(Color.RED);			
		chart.getToolTip().setCurrentXY(x,y);		
		chart.getToolTip().addToolTip(" key:" +  pData.getKey() +
										" Label:" + pData.getLabel(),mPaintToolTip);	
		this.invalidate();*/
}
Also used : ArcPosition(org.xclcharts.event.click.ArcPosition) PieData(org.xclcharts.chart.PieData)

Aggregations

ArcPosition (org.xclcharts.event.click.ArcPosition)6 PieData (org.xclcharts.chart.PieData)5 Paint (android.graphics.Paint)2 PointF (android.graphics.PointF)2 DisplayMetrics (android.util.DisplayMetrics)1 ViewGroup (android.view.ViewGroup)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 FrameLayout (android.widget.FrameLayout)1 RelativeLayout (android.widget.RelativeLayout)1 ChartArcListener (org.xclcharts.event.click.ChartArcListener)1