barChart starts from Middle of Screen instead of Top , why?

走远了吗. 提交于 2020-01-03 04:51:13

问题


When I have set height of barChart to screenHeight then the chart starts from middel of screen ,it should start from top of Screen and its screenshot is attached

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

This is new image with component Inspector and there is no any spacing

来源:https://stackoverflow.com/questions/48483224/barchart-starts-from-middle-of-screen-instead-of-top-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!