将脚本更新为2.5.2

时间:2017-02-01 17:56:19

标签: zingchart

我今天将ZingChart脚本的实例更新到版本2.5.2,这样做会导致标签从之前显示的图表中消失。我不确定我的JSON是否存在问题,只是设法不在先前版本的ZingChart中抛出任何错误,或者它是当前版本的错误。 之前: enter image description here

在: enter image description here

我的JSON:

var maxYValue = 60;
                            var value1 = 40;
                            var value2 = 15;
                            var value3 = 34;
                            var value4 = 14;
                            var value5 = 20;
                            var zones_1 = {
                                "type": "mixed",
                                "font-family": "proxima_nova_rgregular",
                                "title": {
                                    "text": "MINUTES <b>IN ZONES</b>",
                                    "font-family": "proxima_nova_rgregular",
                                    "background-color": "none",
                                    "font-color": "#39393d",
                                    "font-size": "22px",
                                    "adjustLayout": true,
                                    "padding-bottom": 50
                                },
                                "plot": {
                                    "borderRadius": "5px 5px 0 0",
                                    "bar-width": '50%',
                                    "animation": {
                                        "delay": 300,
                                        "effect": 11,
                                        "speed": "500",
                                        "method": "0",
                                        "sequence": "3",
                                        "z-index": 2
                                    },
                                    "value-box": {
                                        "placement": "top-out",
                                        "text": "%v",
                                        "decimals": 0,
                                        "font-color": "#35353b",
                                        "font-size": "14px",
                                        "alpha": 1,
                                        "backgroundColor": "#ffffff",
                                        "padding": "5px 5px 0px 5px",
                                        "shadow": false
                                    }
                                },
                                "plotarea": {
                                    "border-left": "3px solid #39393d",
                                    "border-bottom": "3px solid #39393d",
                                    "padding-left": "3px",
                                    "margin": "dynamic",
                                    "background-color": "none"
                                },
                                "tooltip": {
                                    "visible": false
                                },
                                "scale-x": {
                                    "placement": "opposite",
                                    "line-width": 0,
                                    "tick": {
                                        "visible": false
                                    },
                                    "guide": {
                                        "visible": false
                                    },
                                    "item": {
                                        "visible": false
                                    },
                                },
                                "scale-y": {
                                    "offsetEnd": 45,
                                    "max-value": maxYValue,
                                    "visible": false,
                                    "line-width": 0,
                                    "guide": {
                                        "visible": false
                                    }
                                },
                                "series": [
                                   {
                                       "type": "bar",
                                       "values": [
                                         value1, value2, value3, value4, value5
                                       ],
                                       "background-color": "#cdcccc",
                                       "z-index": 2,
                                       "styles": ['#cdcccc', '#71cbdc', '#8cc541', '#d96c27', '#ea2629']
                                   },
                                   {
                                       "type": "line",
                                       "line-color": "grey",
                                       "marker": { "visible": 0 },
                                       "value-box": { visible: 0 },
                                       "values": [
                                          [0, value1 + 2],
                                          [0, maxYValue],
                                          [0, null],
                                          [1, value2 + 2],
                                          [1, maxYValue],
                                          [1, null],
                                          [2, value3 + 2],
                                          [2, maxYValue],
                                          [2, null],
                                          [3, value4 + 2],
                                          [3, maxYValue],
                                          [3, null],
                                          [4, value5 + 2],
                                          [4, maxYValue],
                                          [4, null],
                                       ]
                                   }
                                ],
                                "labels": [
                                    {
                                        "text": "Zone 1",
                                        "font-size": "13px",
                                        "padding": "10px 5px",
                                        "borderWidth": 1,
                                        "borderColor": "#ffffff",
                                        "backgroundColor": "#ffffff",
                                        "callout": true,
                                        "calloutWidth": 0,
                                        "calloutHeight": 5,
                                        'hook': 'scale:name=scale-x,index=0',
                                        'offset-y': -200,
                                        "calloutTip": {
                                            'offset-y': -200,
                                            "type": "circle",
                                            "background-color": "#fff",
                                            "border-width": 2,
                                            "border-color": "#35353b",
                                            "size": 7,
                                            "shadow": false
                                        }
                                    },
                                    {
                                        "text": "Zone 2",
                                        "font-size": "13px",
                                        "padding": "10px 5px",
                                        "borderWidth": 1,
                                        "borderColor": "#ffffff",
                                        "backgroundColor": "#ffffff",
                                        "callout": true,
                                        "calloutWidth": 0,
                                        "calloutHeight": 5,
                                        'hook': 'scale:name=scale-x,index=1',
                                        'offset-y': -200,
                                        "calloutTip": {
                                            'offset-y': -200,
                                            "type": "circle",
                                            "background-color": "#fff",
                                            "border-width": 2,
                                            "border-color": "#35353b",
                                            "size": 7,
                                            "shadow": false
                                        }
                                    },
                                    {
                                        "text": "Zone 3",
                                        "font-size": "13px",
                                        "padding": "10px 5px",
                                        "borderWidth": 1,
                                        "borderColor": "#ffffff",
                                        "backgroundColor": "#ffffff",
                                        "callout": true,
                                        "calloutWidth": 0,
                                        "calloutHeight": 5,
                                        'hook': 'scale:name=scale-x,index=2',
                                        'offset-y': -200,
                                        "calloutTip": {
                                            'offset-y': -200,
                                            "type": "circle",
                                            "background-color": "#fff",
                                            "border-width": 2,
                                            "border-color": "#35353b",
                                            "size": 7,
                                            "shadow": false
                                        }
                                    },
                                    {
                                        "text": "Zone 4",
                                        "font-size": "13px",
                                        "padding": "10px 5px",
                                        "borderWidth": 1,
                                        "borderColor": "#ffffff",
                                        "backgroundColor": "#ffffff",
                                        "callout": true,
                                        "calloutWidth": 0,
                                        "calloutHeight": 5,
                                        'hook': 'scale:name=scale-x,index=3',
                                        'offset-y': -200,
                                        "calloutTip": {
                                            'offset-y': -200,
                                            "type": "circle",
                                            "background-color": "#fff",
                                            "border-width": 2,
                                            "border-color": "#35353b",
                                            "size": 7,
                                            "shadow": false
                                        }
                                    },
                                    {
                                        "text": "Zone 5",
                                        "font-size": "13px",
                                        "padding": "10px 5px",
                                        "borderWidth": 1,
                                        "borderColor": "#ffffff",
                                        "backgroundColor": "#ffffff",
                                        "callout": true,
                                        "calloutWidth": 0,
                                        "calloutHeight": 5,
                                        'hook': 'scale:name=scale-x,index=4',
                                        'offset-y': -200,
                                        "calloutTip": {
                                            'offset-y': -200,
                                            "type": "circle",
                                            "background-color": "#fff",
                                            "border-width": 2,
                                            "border-color": "#35353b",
                                            "size": 7,
                                            "shadow": false
                                        }
                                    }
                                ],
                            }

非常感谢任何帮助。我希望保留最新版本的脚本,但确实需要这些标签。

2 个答案:

答案 0 :(得分:1)

我目前无法准确说明您的问题的原因是什么,但我们的团队会调查它。然而,我确实看了你的JSON,我认为你可以更容易地获得你正在寻找的输出。我在下面添加了一个更新的图表配置,它可以在最新版本上运行。

完全披露ZingChart团队。

var maxYValue = 60;
                            var value1 = 40;
                            var value2 = 15;
                            var value3 = 34;
                            var value4 = 14;
                            var value5 = 20;

                            
                    var myConfig ={
                                "type": "mixed",
                                "font-family": "proxima_nova_rgregular",
                                "title": {
                                    "text": "MINUTES <b>IN ZONES</b>",
                                    "font-family": "proxima_nova_rgregular",
                                    "background-color": "none",
                                    "font-color": "#39393d",
                                    "font-size": "22px",
                                    "adjustLayout": true,
                                    "padding-bottom": 50
                                },
                                "plot": {
                                    "borderRadius": "5px 5px 0 0",
                                    "bar-width": '50%',
                                    "animation": {
                                        "delay": 300,
                                        "effect": 11,
                                        "speed": "500",
                                        "method": "0",
                                        "sequence": "3",
                                        "z-index": 2
                                    },
                                    "value-box": {
                                        "placement": "top-out",
                                        "text": "%v",
                                        "decimals": 0,
                                        "font-color": "#35353b",
                                        "font-size": "14px",
                                        "alpha": 1,
                                        "backgroundColor": "#ffffff",
                                        "padding": "5px 5px 0px 5px",
                                        "shadow": false
                                    }
                                },
                                "plotarea": {
                                    "border-left": "3px solid #39393d",
                                    "border-bottom": "3px solid #39393d",
                                    "padding-left": "3px",
                                    "margin": "dynamic",
                                    "background-color": "none"
                                },
                                "tooltip": {
                                    "visible": false
                                },
                                "scale-x": {
                                    "placement": "opposite",
                                    "labels":["Zone 1","Zone 2","Zone 3","Zone 4","Zone 5"],//set zone label here.  Much easier than labals:[]
                                    "line-width": 0,
                                    "tick": {
                                        "visible": false
                                    },
                                    "guide": {
                                        "visible": false
                                    },
                                    "item": {
                                        "offsetY": 25,
                                        "font-size": 12,
                                        "fontColor": 'black',
                                        "bold": true
                                    },
                                },
                                "scale-y": {
                                    "offsetEnd": 45,
                                    "max-value": maxYValue,
                                    "visible": false,
                                    "line-width": 0,
                                    "guide": {
                                        "visible": false
                                    }
                                },
                                "series": [
                                   {
                                       "type": "bar",
                                       "values": [
                                         value1, value2, value3, value4, value5
                                       ],
                                       "background-color": "#cdcccc",
                                       "z-index": 2,
                                       "styles": ['#cdcccc', '#71cbdc', '#8cc541', '#d96c27', '#ea2629']
                                   },
                                   {
                                       "type": "line",
                                       "line-color": "gray",
                                       "marker": { 
                                         "backgroundColor":"white",
                                         "borderWidth": 3,
                                         "borderColor":"gray",
                                         "visible": false,
                                         "rules":[//create marker which is always at the top of line
                                           {
                                             'rule':" %node-index%3 == 1 ",
                                             visible: true,
                                             size: 10
                                           }
                                          ]
                                         
                                       },
                                       "value-box": { 
                                         visible: 0
                                       },
                                       "values": [
                                          [0, value1 + 2],
                                          [0, maxYValue],
                                          [0, null],
                                          [1, value2 + 2],
                                          [1, maxYValue],
                                          [1, null],
                                          [2, value3 + 2],
                                          [2, maxYValue],
                                          [2, null],
                                          [3, value4 + 2],
                                          [3, maxYValue],
                                          [3, null],
                                          [4, value5 + 2],
                                          [4, maxYValue],
                                          [4, null],
                                       ]
                                   }
                                ]
                            };

zingchart.render({ 
	id: 'myChart', 
	data: myConfig, 
	height: '100%', 
	width: '100%' 
});
html, body {
	height:100%;
	width:100%;
	margin:0;
	padding:0;
}
#myChart {
	height:100%;
	width:100%;
	min-height:150px;
}
.zc-ref {
	display:none;
}
<!DOCTYPE html>
<html>
	<head>
		<script src= "https://cdn.zingchart.com/zingchart.min.js"></script>
	<!--Inject End-->
	</head>
	<body>
		<div id="myChart"><a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a></div>
	</body>
</html>

答案 1 :(得分:0)

问题是为标签设置了offset-y属性&amp;标注提示。它需要被删除或设置为零。新的lib代码是正确的,因为scale-x有&#34; placement&#34;:&#34;反对&#34;所以它放在上面(如果你从你将看到的项目中删除visible:false)。

很可能旧代码没有使用比例的正确y位置,这就是为什么你必须使用offset-y来纠正它。