我正在创建一个smartgwt散点图,但我无法让它读取mysql数据库中的数据并显示出来。部分代码如下:
ScatterPlotChart.java
public class ScatterPlotChart {
private static FacetChart scatterPlot;
private static Facet metric;
private static Facet patient;
private static DynamicForm typeForm;
private static SelectItem linesTypeItem;
public static VStack scatterChartStack;
public static VStack getScatterPlot() {
scatterPlot = new FacetChart();
scatterPlot.setData(ResultGrid.dataRecords);
scatterPlot.setID("scatterPlotChart");
metric = new Facet();
metric.setValues(new FacetValue("y"), new FacetValue("x"));
metric.setInlinedValues(true);
metric.setId("metric");
patient = new Facet();
patient.setId("patientID");
scatterPlot.setFacets(metric, patient);
scatterPlot.setValueProperty("y");
scatterPlot.setChartType(ChartType.SCATTER);
scatterPlot.setTitle("Scatter Plot");
scatterPlot.setShowScatterLines(true);
scatterPlot.setDataLineType(DataLineType.SMOOTH);
scatterChartStack = new VStack(15);
scatterChartStack.setWidth100();
scatterChartStack.setHeight(400);
scatterChartStack.addMembers(scatterPlot);
scatterChartStack.setVisible(false);
return scatterChartStack;
}
}
ResultGrid.java
public class ResultGrid {
public static ListGrid resultGrid;
public static Record[] dataRecords;
public static ListGrid getResultGrid() {
resultGrid = new ListGrid();
resultGrid.setAutoFetchData(true);
resultGrid.setShowAllRecords(true);
resultGrid.setCanEdit(false);
resultGrid.setShowRecordComponents(true);
resultGrid.setShowRecordComponentsByCell(true);
resultGrid.setDataSource(DataSource.get("sampledb"));
dataRecords = resultGrid.getRecords();
return resultGrid;
}
}
ResultGrid.java是用于在数据库中显示数据的listgrid,ScatterPlotChart.java用于绘制散点图。在ResultGrid.java中,我有ListGridFields,也设置了字段。我通过dataRecords传递的数据库记录数组。请帮忙!