Back to project page SpunkyCharts.
The source code is released under:
GNU General Public License
If you think the Android project SpunkyCharts listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jogden.spunkycharts.traditionalchart.draw; //from w ww . j a v a2s . c o m /* Copyright (C) 2014 Jonathon Ogden < jeog.dev@gmail.com > This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses. */ import com.jogden.spunkycharts.misc.OHLC; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; public class DrawSemantics_CANDLE extends DrawSemantics_OHLC { static private int upColor = Color.GREEN; static private int downColor = Color.RED; static private Paint upBrush; static private Paint downBrush; static{ upBrush = new Paint(Paint.ANTI_ALIAS_FLAG); upBrush.setColor(upColor); upBrush.setStyle(Paint.Style.FILL); downBrush = new Paint(Paint.ANTI_ALIAS_FLAG); downBrush.setColor(downColor); downBrush.setStyle(Paint.Style.FILL); } public DrawSemantics_CANDLE( Context context, int width, int height, int topBuffer, int bottomBuffer, float displayHigh, float displayLow, int lineColor, int lineThickness, float segThickness ){ super( context, width, height, topBuffer, bottomBuffer, displayHigh, displayLow, lineColor, lineThickness, segThickness ); } @Override public void drawSegment(Canvas canvas,int xPos, OHLC ohlc) { float closeY = displayHigh - ohlc.close; float openY = displayHigh - ohlc.open; float highY = displayHigh - ohlc.high; float lowY = displayHigh - ohlc.low; float diff = ohlc.close - ohlc.open; canvas.drawLine( xPos, (highY*pixPerY) + tBuf, xPos, (Math.max(openY, closeY)*pixPerY) + tBuf, brush ); canvas.drawLine( xPos, (Math.min(openY, closeY)*pixPerY) + tBuf, xPos, (lowY*pixPerY) + tBuf, brush ); canvas.drawRect( (float)xPos - (width/2f) + barBufX, (closeY*pixPerY)+tBuf, (float)xPos + (width/2f) - barBufX, (openY*pixPerY)+tBuf, (diff < 0) ? downBrush : upBrush ); /* if( diff > 0 ) else if( diff < 0) canvas.drawRect( (float)xPos - (width/2f) + barBufX, (openY*pixPerY)+tBuf, (float)xPos + (width/2f) - barBufX, (closeY*pixPerY)+tBuf, downBrush ); else canvas.drawLine( (float)xPos - (width/2f) + barBufX, (closeY*pixPerY) + tBuf, (float)xPos + (width/2f) - barBufX, (closeY*pixPerY) + tBuf, brush ); */ } }