我正在 netbeans 上开发一个 java 应用程序。
我已经使用JTable
.
问题是条形图没有按预期工作。
这是代码JTable
:
public void populateTable(){
DefaultTableModel model = (DefaultTableModel) Table.getModel();
model.setRowCount(0);
for (WorkRequest request: account.getWorkQueue().getWorkRequestList()){
if(request instanceof SmartWatchWorkRequest){
Object[] row = new Object[7];
String condition = ((SmartWatchWorkRequest)request).getCondition();
row[0] = request;
int respiratory = ((SmartWatchWorkRequest)request).getRespiratoryRate();
row[1] = respiratory;
int heart = ((SmartWatchWorkRequest)request).getHeartRate();
row[2] = heart;
int blood = ((SmartWatchWorkRequest)request).getBloodPressure();
row[3] = blood;
float weight = ((SmartWatchWorkRequest)request).getWeight();
row[4] = weight;
row[5] = request.getDate();
row[6] = request.getTime();
model.addRow(row);
}
}
}
这是条形图的代码:
private void createChart()
{
DefaultCategoryDataset vitalSignDataset=new DefaultCategoryDataset();
int selectedRow = Table.getSelectedRow();
WorkRequest request = (WorkRequest) Table.getValueAt(selectedRow, 0);
ArrayList<WorkRequest> List = account.getWorkQueue().getWorkRequestList();
for (WorkRequest vitalSign : List) {
if(vitalSign instanceof SmartWatchWorkRequest){
vitalSignDataset.setValue(((SmartWatchWorkRequest)vitalSign).getRespiratoryRate(),"RR", ((SmartWatchWorkRequest)vitalSign).getDate());
vitalSignDataset.setValue(((SmartWatchWorkRequest)vitalSign).getHeartRate(),"HR", ((SmartWatchWorkRequest)vitalSign).getDate());
vitalSignDataset.setValue(((SmartWatchWorkRequest)vitalSign).getBloodPressure(),"BP", ((SmartWatchWorkRequest)vitalSign).getDate());
vitalSignDataset.setValue(((SmartWatchWorkRequest)vitalSign).getWeight(),"WT", ((SmartWatchWorkRequest)vitalSign).getDate());
}
JFreeChart vitalSignChart= ChartFactory.createBarChart3D("Vital Sign Chart", "Time Stamp", "Rate", vitalSignDataset, PlotOrientation.VERTICAL, true, false, false);
vitalSignChart.setBackgroundPaint(Color.white);
CategoryPlot vitalSignChartPlot = vitalSignChart.getCategoryPlot();
vitalSignChartPlot.setBackgroundPaint(Color.lightGray);
CategoryPlot P=vitalSignChart.getCategoryPlot();
P.setRangeGridlinePaint(Color.BLUE);
ChartFrame frame=new ChartFrame("Vitalsign Bar Chart", vitalSignChart);
frame.setVisible(true);
frame.setSize(500, 500);
}}