Menu

Treemap

2015-10-30
2015-11-02
  • Bruno Bravo

    Bruno Bravo - 2015-10-30

    Hi everyone,

    I'm trying to use Treemap chart and a I am facing an issue using the example in the showcase.

    The problem is that there are no methods called "setLevels", "setLayoutAlgorithm" or "setAlternateStartingDirection" in class "Series".

    So, the code below copied from the showcase produces compilation erros:

     final Chart chart = new Chart()  
            .setChartTitleText("Fruit Consumption"); 
    
             chart.addSeries(chart.createSeries()  
                        .setType(Series.Type.TREEMAP)  
                        .setLayoutAlgorithm(TreemapPlotOptions.LayoutAlgorithm.STRIPES)  
                        .setAlternateStartingDirection(true)  
                        .setLevels(level)  
                        .setPoints(new Point[]{  
                            appleParent,  
                            bananaParent,  
                            orangeParent,  
                            new Point("Anne", 5)  
                                .setParent(appleParent),  
                            new Point("Rick", 3)  
                                .setParent(appleParent),  
                            new Point("Peter", 4)  
                                .setParent(appleParent),  
                            new Point("Anne", 4)  
                                .setParent(bananaParent),  
                            new Point("Rick", 10)  
                                .setParent(bananaParent),  
                            new Point("Peter", 1)  
                                .setParent(bananaParent),  
                            new Point("Anne", 1)  
                                .setParent(orangeParent),  
                            new Point("Rick", 3)  
                                .setParent(orangeParent),  
                            new Point("Peter", 3)  
                                .setParent(orangeParent),  
                            new Point("Susanne", 2)  
                                .setParent("Kiwi")  
                                .setColor("#9EDE00")  
                        })  
                    );  
    

    I am using GWT Highcharts 1.7.0.

     

    Last edit: Bruno Bravo 2015-10-30
  • Shawn Quinn

    Shawn Quinn - 2015-10-30

    Apologies, looks like the source code for that example chart didn't get exported properly. Thanks for letting us know so that we can get that corrected! Here is the correct code example for that chart:

            final Chart chart = new Chart()
                    .setChartTitleText("Fruit Consumption");
    
            //Defining points to act as parents
            final Point appleParent = new Point("Apples")
                    .setColor("#EC2500");
            final Point bananaParent = new Point("Bananas")
                    .setColor("#ECE100");
            final Point orangeParent = new Point("Oranges")
                    .setColor("#EC9800");
    
            chart.addSeries(chart.createSeries()
                    .setType(Series.Type.TREEMAP)
                    .setPlotOptions(new TreemapPlotOptions()
                            .setAlternateStartingDirection(true)
                            .setLayoutAlgorithm(TreemapPlotOptions.LayoutAlgorithm.STRIPES)
                            .setLevels(new TreemapPlotOptions.Level()
                                    .setLevel(1)
                                    .setLayoutAlgorithm(TreemapPlotOptions.LayoutAlgorithm.SLICE_AND_DICE)
                                    .setDataLabels(new DataLabels()
                                            .setEnabled(true)
                                            .setAlign(Labels.Align.LEFT)
                                            .setVerticalAlign(Labels.VerticalAlign.TOP)
                                            .setStyle(new Style()
                                                    .setFontSize("15px")
                                                    .setFontWeight("bold")
                                            )
                                    )
                            )
                    )
                    .setPoints(new Point[]{
                            appleParent,
                            bananaParent,
                            orangeParent,
                            new Point("Anne", 5)
                                    .setParent(appleParent),
                            new Point("Rick", 3)
                                    .setParent(appleParent),
                            new Point("Peter", 4)
                                    .setParent(appleParent),
                            new Point("Anne", 4)
                                    .setParent(bananaParent),
                            new Point("Rick", 10)
                                    .setParent(bananaParent),
                            new Point("Peter", 1)
                                    .setParent(bananaParent),
                            new Point("Anne", 1)
                                    .setParent(orangeParent),
                            new Point("Rick", 3)
                                    .setParent(orangeParent),
                            new Point("Peter", 3)
                                    .setParent(orangeParent),
                            new Point("Susanne", 2)
                                    .setParent("Kiwi")
                                    .setColor("#9EDE00")
                    })
            );
    
     
  • Cory Skowronek

    Cory Skowronek - 2015-10-30

    Hi Bruno,

    It looks like the source provided on that example is a bit out of sync. The setLevels() method actually exists in the TreemapPlotOptions class. Try something like this:

     chart.addSeries(chart.createSeries()
                    .setType(Series.Type.TREEMAP)
                    .setPlotOptions(new TreemapPlotOptions()
                            .setAlternateStartingDirection(true)
                            .setLayoutAlgorithm(TreemapPlotOptions.LayoutAlgorithm.STRIPES)
                            .setLevels(new TreemapPlotOptions.Level()
                                    .setLevel(1)
                                    .setLayoutAlgorithm(TreemapPlotOptions.LayoutAlgorithm.SLICE_AND_DICE)
                                    .setDataLabels(new DataLabels()
                                            .setEnabled(true)
                                            .setAlign(Labels.Align.LEFT)
                                            .setVerticalAlign(Labels.VerticalAlign.TOP)
                                            .setStyle(new Style()
                                                    .setFontSize("15px")
                                                    .setFontWeight("bold")
                                            )
                                    )
                            )
                    )
                    .setPoints(
                    ...
                    ...
    
     
  • Bruno Bravo

    Bruno Bravo - 2015-11-02

    I've got it.

    Thanks, Shawn and Cory, for helping me.

     

Log in to post a comment.