0

我正在 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);

}}
4

1 回答 1

0

首先,您的行不是同一种对象。第一行是 WorkRequest 对象,您的第二行是整数等。WorkRequest request = (WorkRequest) Table.getValueAt(selectedRow, 0);当您选择除第一行以外的任何行时,您应该在运行时在该行中获得 ClassCastException。通常模型包含相似对象的列表。

于 2015-12-10T19:23:48.737 回答