I was wondering if someone can help with the horizontal bar chart. I created it following the example source in the widegt explorer.

I wish to set the range depending on the data.

For example, if the maximum value is more than ten, I want the x axis to step in increments of 1 or 2. However, when I do this, the bars do not align with the y axis: as you can see below:

barchart.JPG

For some reason, if I change the range to step by 0.5 (rather than 1) the y axis renders correctly. However, as you can see from the next image, the labels along the x axis become unreadable:

barchart1.JPG

If was to stick with having the steps be 0.5, to keep the y axis rendering correctly, is there a way to set the x axis to only display every second label, so that they are readable?


Below is the code user to build the bar chart:

Code:
private void buildBarChart_Hor(ArrayList<PositionSummaryItem> list){
        Chart chart = new Chart(Registry.get(Service.URL_CHART).toString());
        ChartModel cm = new ChartModel("Portfolio %");
        cm.setBackgroundColour("#fffff5"); 
        
        XAxis xa = new XAxis();
        YAxis ya = new YAxis();
        
        if(list!=null && list.size()>0){
            HorizontalBarChart bar = new HorizontalBarChart();
            bar.setColour("#005791");
            bar.setTooltip("#val#%");
            
            List<String> labels = new ArrayList<String>();
            int i=0;
            for(PositionSummaryItem p : list){
                String colour = ((ArrayList<String>)Registry.get("COLOURS")).get(i);
                i++;
                if(i>((ArrayList<String>)Registry.get("COLOURS")).size()-1){
                    i=0;
                }               
                
                labels.add(0, p.get("name").toString());
                bar.addBars(new HorizontalBarChart.Bar((Double)p.get("percent"), colour));                
            }
            ya.addLabels(labels);
            ya.setGridColour("-1");
            ya.setOffset(true);
            
            double max = Math.round((Double)list.get(0).get("percent"));
            double steps = 0;
            if((Double)list.get(0).get("percent") < 5){
                steps = 0.5;
            }else{
                steps = 0.5;
            }
            xa.setRange(steps, max, steps);            
            xa.setGridColour("#737373");
            
            cm.setXAxis(xa);
            cm.setYAxis(ya);
            cm.setTooltipStyle(new ToolTip(MouseStyle.FOLLOW));  
            
            bar.addChartListener(listener);
            
            cm.addChartConfig(bar);
            chart.setChartModel(cm);
            barContainer.add(chart);            
        }
    }