快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

H5跨平台开发app之横竖屏导致的图表混乱问题-创新互联

在跨平台开发中,犹豫使用的是非原生开发语言,会导致很多不方便的地方,最近公司做一个统计图表的东西,如果用原生开发的话比较容易控制图表显示时手机屏幕的方向,在跨平台开发中比较麻烦,

创新互联的客户来自各行各业,为了共同目标,我们在工作上密切配合,从创业型小企业到企事业单位,感谢他们对我们的要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。专业领域包括成都网站设计、成都做网站、电商网站开发、微信营销、系统平台开发。

如果用户打开了手机屏幕自动旋转,有可能导致图表显示的错误。

解决方案:





    
        
        ichartjs designer
        
        
        
            var evt = "onorientationchange" in window ? "orientationchange" : "resize";

            window.addEventListener(evt, function() {
                console.log(evt);
                var width = document.documentElement.clientWidth;
                var height = document.documentElement.clientHeight;
                $print = $('#ichart-render');
                if(width > height) {
                    $print.width(width);
                    $print.height(height);
                    $print.css('top', 0);
                    $print.css('left', 0);
                    $print.css('transform', 'none');
                    $print.css('transform-origin', '50% 50%');
                    //这里取得了图表显示控件后要对其进行设置CSS,否则来回旋转将导致布局错误
                    var x = document.getElementById("ichart-render");
                    x.style.position = "absolute";
                    x.style.top = "20%";
                } else {
                    $print.width(height);
                    $print.height(width);
                    $print.css('top', 0);
                    $print.css('left', 0);
                    $print.css('transform', 'none');
                    $print.css('transform-origin', '50% 50%');
                }

            }, false);
        
        
            var w = document.documentElement.clientWidth;
            var h = document.documentElement.clientHeight;
            var diameter = Math.min(w, h);
            //这里获得了手机屏幕的宽高后,为了旋转手机的时候导致界面不混乱,需要将显
            示的图表设置为宽高最小的正方形(取巧)
            console.log(diameter);
            $(function() {
                var chart = iChart.create({
                    render: "ichart-render",
                    width: w,
                    height: w,
                    background_color: "#fefefe",
                    gradient: false,
                    color_factor: 0.2,
                    border: {
                        color: "BCBCBC",
                        width: 1
                    },
                    align: "center",
                    offsetx: 0,
                    offsety: 0,
                    sub_option: {
                        border: {
                            color: "#BCBCBC",
                            width: 1
                        },
                        label: {
                            fontweight: 500,
                            fontsize: 11,
                            color: "#4572a7",
                            sign: "square",
                            sign_size: 12,
                            border: {
                                color: "#BCBCBC",
                                width: 1
                            },
                            background_color: "#fefefe"
                        }
                    },
                    shadow: true,
                    shadow_color: "#666666",
                    shadow_blur: 2,
                    showpercent: false,
                    column_width: "70%",
                    bar_height: "70%",
                    radius: "90%",
                    title: {
                        text: "利用ichartjs制作漂亮图表",
                        color: "#111111",
                        fontsize: 20,
                        font: "微软雅黑",
                        textAlign: "center",
                        height: 30,
                        offsetx: 0,
                        offsety: 0
                    },
                    subtitle: {
                        text: "",
                        color: "#111111",
                        fontsize: 16,
                        font: "微软雅黑",
                        textAlign: "center",
                        height: 20,
                        offsetx: 0,
                        offsety: 0
                    },
                    footnote: {
                        text: "",
                        color: "#111111",
                        fontsize: 12,
                        font: "微软雅黑",
                        textAlign: "right",
                        height: 20,
                        offsetx: 0,
                        offsety: 0
                    },
                    legend: {
                        enable: false,
                        background_color: "#fefefe",
                        color: "#333333",
                        fontsize: 12,
                        border: {
                            color: "#BCBCBC",
                            width: 1
                        },
                        column: 1,
                        align: "right",
                        valign: "center",
                        offsetx: 0,
                        offsety: 0
                    },
                    coordinate: {
                        width: "80%",
                        height: "84%",
                        background_color: "#ffffff",
                        axis: {
                            color: "#a5acb8",
                            width: [1, "", 1, ""]
                        },
                        grid_color: "#d9d9d9",
                        label: {
                            fontweight: 500,
                            color: "#666666",
                            fontsize: 11
                        }
                    },
                    label: {
                        fontweight: 500,
                        color: "#666666",
                        fontsize: 11
                    },
                    type: "pie2d",
                    data: [{
                        name: "名称A",
                        value: 20,
                        color: "#4572a7"
                    }, {
                        name: "名称B",
                        value: 30,
                        color: "#aa4643"
                    }, {
                        name: "名称C",
                        value: 40,
                        color: "#89a54e"
                    }, {
                        name: "新增",
                        value: 10,
                        color: "#4572a7"
                    }]
                });
                chart.draw();
            });
        
        
            #ichart-render {
                position: absolute;
                top: 20%;
            }
        
    

    
        
    

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前题目:H5跨平台开发app之横竖屏导致的图表混乱问题-创新互联
标题网址:http://6mz.cn/article/dpohii.html

其他资讯