1

我正在使用 vaadin,对于一些可视化数据分析,我为 vaadin 添加了插件 InvientCharts (https://vaadin.com/directory#addon/invient-charts)。

是否可以动态更改散点图的 x 轴和 y 轴标题(因此在创建图表之后)?

我目前有一个散点图和一个按钮。单击按钮时,所有现有点(系列)将被删除,x 轴和 y 轴标题应更改,新点应添加到图表上。

这是我目前正在尝试的代码片段:

public void changePoints(String xAxisTitle, String yAxisTitle, List<List<double[]>> xAndYCoordinates) {
        // remove all points from the scatterchart - THIS IS WORKING
        Object[] allSeries = chart.getAllSeries().toArray();
        for(int j = 0; j < allSeries.length; j++){
            Series serie = (Series) allSeries[j];
            chart.removeSeries(serie);
        }

        // update the x- and y-axis - THIS IS NOT WORKING AND WHAT I'M TALKING ABOUT
        chartConfig.getXAxes().clear();
        chartConfig.getYAxes().clear();
        NumberXAxis xAxis = new NumberXAxis();
        xAxis.setTitle(new AxisTitle(xAxisTitle));
        xAxis.setStartOnTick(true);
        xAxis.setEndOnTick(true);
        xAxis.setShowLastLabel(true);
        LinkedHashSet<XAxis> xAxesSet = new LinkedHashSet<InvientChartsConfig.XAxis>();
        xAxesSet.add(xAxis);
        chartConfig.setXAxes(xAxesSet);
        NumberYAxis yAxis = new NumberYAxis();
        yAxis.setTitle(new AxisTitle(yAxisTitle));
        LinkedHashSet<YAxis> yAxesSet = new LinkedHashSet<InvientChartsConfig.YAxis>();
        yAxesSet.add(yAxis);
        chartConfig.setYAxes(yAxesSet);


        // add the new points - THIS IS WORKING AGAIN
        for (int i = 0; i < versionDates.size(); i++) {
            String versionDate = versionDates.get(i);
            List<double[]> versionValues = xAndYCoordinates.get(i);

            ScatterConfig versionScatterConfig = new ScatterConfig();
            XYSeries series = new XYSeries("Version " + (i + 1) + " - "
                    + versionDate, versionScatterConfig);
            series.setSeriesPoints(getPoints(series, versionValues));
            chart.addSeries(series);
        }
    }

如您所见,点的删除和添加工作得非常好,我认为这是因为我在这里直接处理图表,而当我尝试更改轴标题时,我正在处理 chartConfig。

您能否告诉或告诉我如何更改现有图表中 x 轴和 y 轴的标题(如上所述)?

非常感谢

4

1 回答 1

1

经过大量研究后,我得出的结论是,目前似乎没有办法动态地更改 x 轴和 y 轴标题,这是可行的。

我发现如果你刷新页面,例如按 F5,坐标轴标题就会改变。我尝试过实施复习,但不知何故行为仍然没有改变。

所以对我来说它看起来像是一个错误(或软件故障)。

My workaround which is doing the same is just removing the whole chart and then adding a completely new one with the new Axis-caption. This works perfectly fast and fine, but is a dirty solution in my eyes, since you have to add more lines of codes than necessary, as well as the logic is now basically more complicated then it should be.

于 2012-09-04T12:44:04.520 回答