package chartb; import java.util.Arrays; import java.util.List; import javafx.application.Application; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.scene.Scene; import javafx.scene.chart.AreaChart; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.scene.control.ContentDisplay; import javafx.scene.control.Label; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn.CellDataFeatures; import javafx.scene.control.TableView; import javafx.stage.Stage; import javafx.util.Callback; import javafx.util.Pair; public class ChartB extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { TableView>> table = new TableView>>(); TableColumn>, String> c1 = new TableColumn>, String>("A"); c1.setCellValueFactory(new Callback>, String>, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures>, String> p) { return new ReadOnlyObjectWrapper(p.getValue().getKey()); } }); TableColumn>, List> c2 = new TableColumn>, List>("B"); c2.setMinWidth(400); c2.setCellFactory(new Callback>, List>, TableCell>, List>>() { @Override public TableCell>, List> call(TableColumn>, List> p) { return new SeriesChartTableCell(); } }); c2.setCellValueFactory(new Callback>, List>, ObservableValue>>() { @Override public ObservableValue> call(CellDataFeatures>, List> p) { return new ReadOnlyObjectWrapper>(p.getValue().getValue()); } }); table.getColumns().addAll(c1,c2); table.setItems(FXCollections.observableArrayList( new Pair>("aaa", Arrays.asList(new Double[]{1d,6d,2d,7d,3d,8d,1d})), new Pair>("bbb", Arrays.asList(new Double[]{1d,6d,2d,7d,3d,8d,1d})), new Pair>("ccc", Arrays.asList(new Double[]{1d,6d,2d,7d,3d,8d,1d})), new Pair>("ddd", Arrays.asList(new Double[]{1d,6d,2d,7d,3d,8d,1d})) )); Scene scene = new Scene(table, 500,400); stage.setScene(scene); stage.show(); } public static class SeriesChartTableCell extends TableCell>, List> { NumberAxis xAxis; NumberAxis yAxis; AreaChart chart; public SeriesChartTableCell() { super(); getStyleClass().add("table-chart-cell"); xAxis = new NumberAxis(); yAxis= new NumberAxis(); chart = new AreaChart(xAxis, yAxis); chart.getStyleClass().add("table-chart"); chart.setLegendVisible(false); chart.setTitle(null); xAxis.setLabel(null); xAxis.setTickMarkVisible(false); xAxis.setMinorTickVisible(false); // UNCOMMENT ME TO CAUSE HANG // xAxis.setTickLabelsVisible(false); chart.setMinSize(400,80); chart.setPrefSize(400,80); setGraphic(chart); setContentDisplay(ContentDisplay.GRAPHIC_ONLY); } @Override public void updateItem(List item, boolean empty) { super.updateItem(item, empty); if (empty) { setGraphic(null); } else { XYChart.Series salesSeries = new XYChart.Series(); for (int i = 0; i < item.size(); i++) { salesSeries.getData().add(new XYChart.Data(i, item.get(i))); } chart.getData().setAll(salesSeries); setContentDisplay(ContentDisplay.GRAPHIC_ONLY); } } } }