简体   繁体   English

如何摆脱饼图周围多余的空白? 使用 amcharts 4 库

[英]How do I get rid of the excess white space around pie chart? Using amcharts 4 libs

I have been trying to spread the pie chart I have to cover most of the 'card' I on the page, but no matter how much margin I cut, it either start disappearing behind another border within the card.我一直在尝试传播饼图,我必须覆盖页面上的大部分“卡片”,但无论我削减多少边距,它要么开始消失在卡片内的另一个边框后面。 I noticed that amcharts lib creates a bunch of layers that the developer doesn't have much control over.我注意到 amcharts lib 创建了一堆开发人员无法控制的层。 Anyway, this is what I'm talking about:无论如何,这就是我要说的: 在此处输入图像描述

Here is the generated HTML code snippet:这是生成的 HTML 代码片段: 在此处输入图像描述

Here is my javascript:这是我的 javascript:

 am4core.ready(function () {

            //Themes                
            var chartType = am4charts.PieChart3D;
            var seriesType = new am4charts.PieSeries3D();
        
            //Create Chart and Series 
            var chart = createChart(thisWidget.id, chartType);

            var pieSeries = chart.series.push(seriesType); // 3D Pie Chart

            //Set properties
            chart.hiddenState.properties.opacity = 0; // 3D Pie Chart: this creates initial fade-in
            
            pieSeries.slices.template.cornerRadius = 6;  //Pie Chart with varying Radius + 3D
            pieSeries.colors.step = 3;  //Pie Chart with varying Radius + 3D
            pieSeries.angle = 45;

            //color
            if (colorTheme) {
                pieSeries.colors.list = getAmchartCustomTheme(colorTheme);
            }
                
            //data types 
            pieSeries.dataFields.value = "count";
            pieSeries.dataFields.category = "tag";
            chart.paddingTop = 0;
            chart.marginTop = 0;
            
            // Put a thick white border around each Slice
            pieSeries.slices.template.stroke = am4core.color("#fff");
            pieSeries.slices.template
                // change the cursor on hover to make it apparent the object can be interacted with
                .cursorOverStyle = [
                    {
                        "property": "cursor",
                        "value": "pointer"
                    }
                ];

            //Make the slice move on hover
            var slice = pieSeries.slices.template;
            slice.states.getKey("active").properties.shiftRadius = 0;
            slice.states.getKey("hover").properties.scale = 1;
            slice.states.getKey("hover").properties.shiftRadius = 0.2;

            //increase size of Chart
            chart.svgContainer.htmlElement.style.height = targetHeight;
            chart.svgContainer.autoresize = true;

            //disable Ticks and labels to save space
            pieSeries.labels.template.disabled = true;

            //registering events
            pieSeries.slices.template.events.on("hit", function (ev) {
                var category = ev.target.slice._dataItem.properties.category;
                addInput(category);
            });
            pieSeries.alignLabels = false;       

            // Create a base filter effect (as if it's not there) for the hover to return to
            var shadow = pieSeries.slices.template.filters.push(new am4core.DropShadowFilter);
            shadow.opacity = 0;

            // Create hover state
            var hoverState = pieSeries.slices.template.states.getKey("hover"); // normally we have to create the hover state, in this case it already exists

            // Slightly shift the shadow and make it more prominent on hover
            var hoverShadow = hoverState.filters.push(new am4core.DropShadowFilter);
            hoverShadow.opacity = 0.7;
            hoverShadow.blur = 5;

            //Add Data
            chart.data = displayItems;
           
        })
        
    

strokeOpacity = 0 or strokeWidth = 0 should do the trick. strokeOpacity = 0 or strokeWidth = 0应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM