简体   繁体   English

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

[英]Is it possible to change the x- and y-axis caption dynamically with the vaadin addon InvientCharts

I am using vaadin and for some visual data analysis I've added the addon InvientCharts for vaadin (https://vaadin.com/directory#addon/invient-charts). 我正在使用vaadin,并且为了进行一些可视化数据分析,我为vaadin添加了插件InvientCharts(https://vaadin.com/directory#addon/invient-charts)。

Is it possible to dynamically change the x- and y-axis Caption of the scattertchart (so after the chart has been created)? 是否可以动态更改散点图的x轴和y轴标题(因此在创建图表之后)?

I'm currently having a scatterchart and a button. 我目前有一个散点图和一个按钮。 When the button is clicked, all existing points (Series) shall be removed, the x- and y-axis caption shall change and the new points shall be added on the chart. 单击该按钮时,应删除所有现有点(系列),x和y轴标题应更改,新点应添加到图表上。

That's the code snippet with which I'm trying it currently: 那是我目前正在尝试的代码片段:

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);
        }
    }

As you can see, the removing and adding of points works perfectly fine, which I assume is because I'm working directly on the chart here, while I'm working on the chartConfig when I try to change the axes caption. 如您所见,删除和添加点的工作非常好,我认为这是因为我在这里直接在图表上工作,而在我尝试更改轴标题时在chartConfig上工作。

Could you please tell or show me how I can change the caption of the x- and y-Axis in an already existing chart (As described above)? 您能否告诉或告诉我如何更改现有图表中的x和y轴标题(如上所述)?

Thanks a lot 非常感谢

After a lot of research I've come to the conclusion that there seems to be currently no way of changing the x- and yAxis caption dnymically, which works. 经过大量研究,我得出的结论是,目前似乎没有办法以对称方式更改x-和yAxis标题,这是可行的。

I found out that if you refresh the page, eg by pressing F5, the axes caption gets changed. 我发现,如果刷新页面(例如,按F5键),则会更改轴标题。 I've tried implementing a refresher, but somehow the behaviour still didn't change. 我尝试过实施更新,但是某种程度上行为仍然没有改变。

So it looks like a bug (or software failure) for me. 因此,对我来说,这似乎是一个bug(或软件故障)。

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. 我的解决方法是删除整个图表,然后使用新的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. 这可以完美快速,良好地工作,但是在我眼中是一个肮脏的解决方案,因为您必须添加不必要的代码行,而且现在的逻辑实际上比应该的复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM