是否可以使用vaadin插件InvientCharts动态更改x轴和y轴标题

时间:2012-08-27 13:43:20

标签: java visualization vaadin add-on scatter-plot

我正在使用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轴的标题(如上所述)?

非常感谢

1 个答案:

答案 0 :(得分:1)

经过大量研究后,我得出的结论是,目前似乎没有办法改变x-和yAxis标题,这是有效的。

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

所以它看起来像是一个bug(或软件失败)。

我的解决方法就是删除整个图表,然后使用新的Axis-caption添加一个全新的图表。这种方法非常快速和精细,但是在我眼中是一个肮脏的解决方案,因为你必须添加比必要更多的代码行,以及逻辑现在基本上应该更加复杂。