java拓扑开发_Java拓扑图开发-带宽示例

/**

* 区域图表

*

* @author Administrator

*

*/

public class AreaChart extends JComponent {

public AreaChart() {

}

@Override

protected void paintComponent(Graphics g) {

Graphics2D g2d = (Graphics2D) g;

int width = this.getWidth();

int height = this.getHeight();

g2d.setColor(this.background);

g2d.fillRect(0, 0, width, height);

double gridCellWidth = width * this.gridCellPercent;

double gridCellHeight = height * this.gridCellPercent;

g2d.setColor(this.gridColor);

g2d.setStroke(this.gridStroke);

for (int x = 0; x < width; x += gridCellWidth) {

g2d.drawLine(x, 0, x, height);

}

for (int y = 0; y < height; y += gridCellHeight) {

g2d.drawLine(0, y, width, y);

}

double x = 0;

double y = height;

final double delta = this.maxValue - this.minValue;

GeneralPath path = new GeneralPath();

path.moveTo(x, y);

for (int index = 0; index < this.values.size(); index++) {

double value = this.values.get(index);

x += gridCellWidth;

y = height - (value - this.minValue) / delta * height;

path.lineTo(x, y);

}

path.lineTo(width, height);

path.closePath();

g2d.setColor(this.areaColor);

g2d.fill(path);

}

public void setBackground(Color background) {

this.background = background;

}

public void addValue(double value) {

if (this.values.size() >= maxCount) {

this.values.remove(0);

}

if (this.maxValue < value) {

this.maxValue = value;

}

if (this.minValue > value) {

this.minValue = value;

}

this.values.add(value);

}

public void setVal

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值