barChart从Screen of Middle而不是Top开始,为什么?

时间:2018-01-28 04:42:34

标签: java bar-chart codenameone

当我将barChart的高度设置为screenHeight然后图表从屏幕的middel开始时,它应该从屏幕的顶部开始并且其屏幕截图已附加enter image description here

Tabs chartTabs = new Tabs();
  chartTabs.setPreferredH(screenHeight);
chartTabs.addTab("", icon1, new BarChartGenerator().getBarChart(dealersNames, dealersValues));


public Component getBarChart(ArrayList<ArrayList<String>> nameList, ArrayList<ArrayList<Double>> valueList) {
        String[] titles = new String[]{"2017"};

        XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
        renderer.setOrientation(Orientation.VERTICAL);

        double largeValue = getMax(valueList.get(0)) * 1.1;
        System.out.println(" large " + largeValue);
        int nameSize = 0;
        for (ArrayList<String> nameArray : nameList) {
            int index = 0;
            nameSize = nameArray.size();
            for (String name : nameArray) {
//                if ((index / 2) != 0) {
                renderer.addXTextLabel(index + 1, name);
                index++;
//                }
            }

        }
//        nameSize = 
        int endXValue = (int) (nameSize + 1);
        setChartSettings(renderer, "", "", "", 0,
                endXValue, 0, largeValue, ColorUtil.GREEN, ColorUtil.GREEN);
        renderer.setXLabels(1);
        renderer.setYLabels(8);

        initRendererer(renderer);
        int length = renderer.getSeriesRendererCount();
        for (int i = 0; i < length; i++) {
            XYSeriesRenderer seriesRenderer = (XYSeriesRenderer) renderer.getSeriesRendererAt(i);
            seriesRenderer.setDisplayChartValues(true);
        }

//        renderer.setYLabelsAlign(Component.LEFT);
        renderer.setXLabelsAlign(Component.RIGHT);

        renderer.setXLabelsAngle(0);
//        renderer.setXAxisMax(10);
        renderer.setShowTickMarks(true);
//        renderer.setBarWidth(50);
//        renderer.setYAxisAlign(Component.CENTER);

        BarChart chart = new BarChart(buildBarDataset2(titles, valueList), renderer,
                Type.DEFAULT) {

                    @Override
                    public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint) {
                        super.draw(canvas, width / 4, y, width, height, paint); //To change body of generated methods, choose Tools | Templates.
                    }

                };

        return newChart(chart);
    }

这是带有组件Inspector的新图像,没有任何间距 inspector image

0 个答案:

没有答案