0

I use Cesiumjs to create a bar chart. I don't understand why there is a gap in the bar? Code Link

enter image description here

        var viewer = new Cesium.Viewer('cesiumContainer');
        viewer.scene.globe.depthTestAgainstTerrain = true;
        var alt = 0;
        var height = 1204.5894586894588;
        var blueBox = viewer.entities.add({
            name: "1",
            position: Cesium.Cartesian3.fromDegrees(-122, 37.5, alt),
            box: {
                dimensions: new Cesium.Cartesian3(4000 / 20.0, 3000.0 / 20, height),
                material: Cesium.Color.YELLOW
            }
        });
        alt += height;
        height = 1141.9837105171814;
        var blueBox = viewer.entities.add({
            name: "2",
            position: Cesium.Cartesian3.fromDegrees(-122, 37.5, alt),
            box: {
                dimensions: new Cesium.Cartesian3(4000 / 20.0, 3000.0 / 20, height),
                material: Cesium.Color.BLUE
            }
        });
        alt += height;
        height = 1676.1912919343326;
        var blueBox = viewer.entities.add({
            name: "3",
            position: Cesium.Cartesian3.fromDegrees(-122, 37.5, alt),
            box: {
                dimensions: new Cesium.Cartesian3(4000 / 20.0, 3000.0 / 20, height),
                material: Cesium.Color.RED
            }
        });
        alt += height;
        height = 1199.65;

        var blueBox = viewer.entities.add({
            name: "4",
            position: Cesium.Cartesian3.fromDegrees(-122, 37.5, alt),
            box: {
                dimensions: new Cesium.Cartesian3(4000 / 20.0, 3000.0 / 20, height),
                material: Cesium.Color.GRREN
            }
        });
        viewer.zoomTo(viewer.entities);
        /*var outlineOnly = viewer.entities.add({
         name : 'Yellow box outline',
         position: Cesium.Cartesian3.fromDegrees(-100.0, 40.0, 300000.0),
         box : {
         dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
         fill : false,
         outline : true,
         outlineColor : Cesium.Color.YELLOW
         }
         });*/

        viewer.zoomTo(viewer.entities);

1 Answer 1

2

I think the position property should be the center of the cubes. Try with

Cesium.Cartesian3.fromDegrees(-122, 37.5, alt+height/2)

as position

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.