gpt4 book ai didi

java - 饼图未显示预期输出

转载 作者:行者123 更新时间:2023-11-30 07:28:00 25 4
gpt4 key购买 nike

我试图使我的饼图与模拟器运行期间更改的数据保持同步。

我的问题是饼图没有以正确的方式显示数据,我不知道问题是什么。

 public void paintComponent(Graphics g) {
super.paintComponent(g);

int totalAmountOfCars = this.adhocCars + this.reservationCars + this.parkpassCars;
float percentageAdHoc = totalAmountOfCars <= 0 || this.adhocCars <= 0 ? 0 : adhocCars/totalAmountOfCars * 100;
float percentageParkPass = totalAmountOfCars <= 0 || this.parkpassCars <= 0 ? 0 :parkpassCars/totalAmountOfCars * 100;
float percentageReservation = totalAmountOfCars <= 0 || this.reservationCars <= 0 ? 0 :reservationCars/totalAmountOfCars * 100;


float adHocAngle = totalAmountOfCars <= 0 || this.adhocCars <= 0 ? 0 : 360/percentageAdHoc*100;
float parkPassAngle = totalAmountOfCars <= 0 || this.parkpassCars <= 0 ? 0 : 360/percentageParkPass*100;
float reservationAngle = totalAmountOfCars <= 0 || this.reservationCars <= 0 ? 0 : 360/percentageReservation*100;

Dimension prefSize = this.getPreferredSize();
g.setColor(Color.WHITE);
g.fillRect(prefSize.width/2, prefSize.height/2, 200, 200);

这里我计算弧的角度..

g.setColor(Color.RED);
g.fillArc(prefSize.width/2 + 10, prefSize.height/2 + 10, 180, 180, 0,(int)adHocAngle);
g.setColor(Color.BLUE);
g.fillArc(prefSize.width/2 + 10, prefSize.height/2 + 10, 180, 180, (int)adHocAngle, (int)adHocAngle+(int)parkPassAngle);
g.setColor(Color.ORANGE);
g.fillArc(prefSize.width/2 + 10, prefSize.height/2 + 10, 180, 180,(int)adHocAngle+(int)parkPassAngle, (int)reservationAngle);

这部分应该填充它,在某些情况下,整个字符填充为橙色,而在其他情况下,它为 99% 红色,并带有一条细小的蓝色线。而不是例如 30%、40%、30%。

黄色图表:
enter image description here

红/蓝图表:
enter image description here

最佳答案

也许您想首先确保百分比计算正确。

adhocCars/totalAmountOfCars * 100;

应该是

100/totalAmountOfCars * adhocCars;

关于java - 饼图未显示预期输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36548562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com