Re: [請益] 有K棒製作程式嗎?

作者: xisland (窄宅)   2013-05-27 12:30:53
※ 引述《dichotomyptt ((  ̄ c ̄)y▂ξ)》之銘言:
: 如題
: 我想要請問一下 有沒有K棒製作程式
: 可以 自由填入X軸 Y軸
: 跟下面的成交量 有均線更佳
: 謝謝^^
很久以前找到的程式碼,原作好像不是java,我改成寫成java,並加上註解
import java.awt.*;
import java.awt.event.*;
public class stock extends Frame
{
char [] dashline=new char [200];
int span=6; //寬的間距
int height=500; //圖高
int start=120; //X座標起點
int width=8; //長方形寬
int end=750; //X座標終點
int height_span=50; //高的間距
int max; //最大值
int min; //最小值
int scale=0;
int ss;
int es;
int hs;
int ls;
int xL;
int totspan;
int stock_data[][]=
{
//開盤, 收盤, 當天最高, 當天最低
{313 ,331 ,333 ,311 },
{324 ,330 ,335 ,323 },
{335 ,329 ,337 ,328 },
{329 ,341 ,342 ,327 },
{341 ,328 ,343 ,328 },
{328 ,318 ,330 ,315 },
{320 ,321 ,326 ,320 },
{319 ,321 ,327 ,315 },
{325 ,335 ,335 ,323 },
{344 ,335 ,348 ,335 },
{338 ,358 ,358 ,333 },
{360 ,351 ,365 ,350 },
{355 ,346 ,356 ,345 },
{347 ,356 ,360 ,346 },
{356 ,353 ,362 ,352 },
{357 ,345 ,360 ,342 },
{344 ,338 ,348 ,338 },
{333 ,324 ,336 ,318 },
{332 ,321 ,334 ,321 },
{316 ,326 ,328 ,315 },
{328 ,318 ,332 ,318 },
{324 ,330 ,330 ,318 },
{332 ,329 ,333 ,327 },
{334 ,326 ,336 ,326 },
{324 ,318 ,324 ,318 },
{317 ,321 ,323 ,316 },
{326 ,326 ,329 ,324 },
{338 ,328 ,340 ,328 },
{333 ,333 ,337 ,330 },
{335 ,334 ,335 ,330 },
{334 ,331 ,338 ,330 },
{331 ,322 ,332 ,321 },
{323 ,325 ,327 ,316 },
{324 ,318 ,324 ,317 },
{318 ,310 ,322 ,310 },
{313 ,296 ,317 ,293 },
{295 ,302 ,302 ,291 },
{288 ,286 ,290 ,283 }
};
public stock()
{
super("股票行情");
setSize(800,600);
setResizable(false); //不可改變大小
addWindowListener(new WindowAdapter() //匿名的視窗事件調適器
{
public void windowClosing(WindowEvent e) //視窗關閉事件
{
dispose(); // 釋放視窗所佔用的資源, 並關閉視窗
}
});
for(int i=0;i<200;i++)
dashline[i]='-';
}
public void paint (Graphics g)
{
int i,j,k;
max = 0;
for(j=0;j<stock_data.length;j++)
{
if (stock_data[j][2]>max) //求最大值
max = stock_data[j][2];
}
min = max;
for(j=0;j<stock_data.length;j++)
{
if (stock_data[j][3]<min) //求最小值
min = stock_data[j][3];
}
scale=height/(max-min);
g.drawString("max=" + max,110,60); // 寫出最大值
g.drawString("min=" + min,110,80); // 寫出最小值
g.drawString("height/max-min=" + scale,110,120); //寫出刻度
for( k=0;k<10;k++) // 分10個橫線
{
int number=min+(scale*k);
g.drawChars(dashline,0,200,
0,height-(k*height_span)); // 畫出橫的虛線
g.drawString(k + "->" + number ,
start - 70,
height-((height_span*k)+5)); //橫線代表的數值
}
for(i=0;i<stock_data.length;i++)
{
ss = stock_data[i][0]; // 開盤
es = stock_data[i][1]; // 收盤
hs = stock_data[i][2]; // 當天最高
ls = stock_data[i][3]; // 當天最低
xL= start+(width*i);
totspan = span*(i-1);
if(es>ss) //收盤大於開盤
{
g.setColor(Color.red);
g.fillRect(xL+totspan,
height-((es-min)*scale),
width,
(es-ss)*scale);
g.setColor(Color.black);
g.drawLine((xL*2+totspan+(span*i))/2,
height-((hs-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((es-min)*scale));
g.drawLine((xL*2+totspan+(span*i))/2,
height-((ls-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((ss-min)*scale));
}
else if(ss>es) //開盤大於收盤
{
g.setColor(Color.green);
g.fillRect(xL+totspan,
height-((ss-min)*scale),
width,
(ss-es)*scale);
g.setColor(Color.black);
g.drawLine((xL*2+totspan+(span*i))/2,
height-((hs-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((ss-min)*scale));
g.drawLine((xL*2+totspan+(span*i))/2,
height-((ls-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((es-min)*scale));
}
else //開盤等於收盤
{
g.setColor(Color.black);
g.fillRect(xL+totspan,
height-((ss-min)*scale),
width,
1);
g.drawLine((xL*2+totspan+(span*i))/2,
height-((hs-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((ss-min)*scale));
g.drawLine((xL*2+totspan+(span*i))/2,
height-((ls-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((es-min)*scale));
}
}
}
}
作者: dichotomyptt ((  ̄ c ̄)y▂ξ)   2013-05-27 12:38:00
我去問我朋友看看T_T 先謝謝你
作者: dichotomyptt ((  ̄ c ̄)y▂ξ)   2013-05-27 14:04:00
那也要他會啊 他只會簡單的EXCEL而以
作者: kanyewest927 (bicyclego)   2013-05-27 14:38:00
看不懂啦!怒吃便當

Links booklink

Contact Us: admin [ a t ] ucptt.com