2016-12-22 2 views
4

Я пытаюсь воссоздать следующую с ZingChart: enter image description hereМожно ли отображать фигуры за сериями/графиками?

До сих пор, у меня есть все, кроме серых линий между кончиками выноски этикеток и верхней решеткой. Я попытался создать линии, используя фигуры, но независимо от установки z-индекса формы всегда появляются поверх баров: enter image description here

Возможно ли разместить фигуры за участками? Если нет, есть ли другой способ достичь этого дизайна?

Мой JSON thusfar:

var myConfig = { 
 
    "type":"bar", 
 
"labels":[ 
 
    { 
 
     "text":"Zone 1", 
 
     "font-size":"13px", 
 
     "x":"5%", 
 
     "y":"20%", 
 
     "height":"15%", 
 
     "width":"20%", 
 
     "borderWidth":1, 
 
     "borderColor":"#ffffff", 
 
     "callout":true, 
 
     "calloutWidth":0, 
 
     "calloutHeight":5, 
 
     "calloutTip":{ 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
     } 
 
    }, 
 
    { 
 
     "text":"Zone 2", 
 
     "font-size":"13px", 
 
     "x":"23%", 
 
     "y":"20%", 
 
     "height":"15%", 
 
     "width":"20%", 
 
     "borderWidth":1, 
 
     "borderColor":"#ffffff", 
 
     "callout":true, 
 
     "calloutWidth":0, 
 
     "calloutHeight":5, 
 
     "calloutTip":{ 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
     } 
 
    }, 
 
    { 
 
     "text":"Zone 3", 
 
     "font-size":"13px", 
 
     "x":"40%", 
 
     "y":"20%", 
 
     "height":"15%", 
 
     "width":"20%", 
 
     "borderWidth":1, 
 
     "borderColor":"#ffffff", 
 
     "callout":true, 
 
     "calloutWidth":0, 
 
     "calloutHeight":5, 
 
     "calloutTip":{ 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
     } 
 
    }, 
 
    { 
 
     "text":"Zone 4", 
 
     "font-size":"13px", 
 
     "x":"57%", 
 
     "y":"20%", 
 
     "height":"15%", 
 
     "width":"20%", 
 
     "borderWidth":1, 
 
     "borderColor":"#ffffff", 
 
     "callout":true, 
 
     "calloutWidth":0, 
 
     "calloutHeight":5, 
 
     "calloutTip":{ 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
     } 
 
    }, 
 
    { 
 
     "text":"Zone 5", 
 
     "font-size":"13px", 
 
     "x":"75%", 
 
     "y":"20%", 
 
     "height":"15%", 
 
     "width":"20%", 
 
     "borderWidth":1, 
 
     "borderColor":"#ffffff", 
 
     "callout":true, 
 
     "calloutWidth":0, 
 
     "calloutHeight":5, 
 
     "calloutTip":{ 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
     } 
 
    } 
 
], 
 
"shapes":[ 
 
    { 
 
     "type":"line", 
 
     "line-color":"#5297b6", 
 
     "line-width":2, 
 
     "points":[ 
 
     [ 
 
      75, 
 
      75 
 
     ], 
 
     [ 
 
      75, 
 
      320 
 
     ] 
 
     ], 
 
     "z-index":1, 
 
     "placement":"bottom" 
 
    } 
 
], 
 
"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, 
 
    "height":"175px", 
 
    "padding-bottom":"70px" 
 
}, 
 
"mediaRules":[ 
 
    { 
 
     maxWidth:564, 
 
     "width":"100%" 
 
    }, 
 
    { 
 
     "minWidth":565, 
 
     "width":"565px" 
 
    } 
 
], 
 
"plot":{ 
 
    "borderRadius":"5px 5px 0 0", 
 
    "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", 
 
     "shadow":false 
 
    } 
 
}, 
 
"plotarea":{ 
 
    "border-left":"3px solid #39393d", 
 
    "padding-left":"3px", 
 
    "margin":"0 0 0 3px", 
 
    "background-color":"none" 
 
}, 
 
"background-image":"http://www.fitmetrix.io/images/classListZoneChartBg.png", 
 
"background-repeat":"no-repeat", 
 
"background-position":"bottom left", 
 
"scale-x":{ 
 
    "line-color":"#39393d", 
 
    "line-width":3, 
 
    "tick":{ 
 
     "visible":false 
 
    }, 
 
    "guide":{ 
 
     "visible":false 
 
    }, 
 
    "item":{ 
 
     "visible":false 
 
    } 
 
}, 
 
"scale-y":{ 
 
    "visible":false, 
 
    "guide":{ 
 
     "visible":false 
 
    } 
 
}, 
 
"series":[ 
 
    { 
 
     "values":[ 
 
     40 
 
     ], 
 
     "bar-width":"50%", 
 
     "background-color":"#cdcccc", 
 
     "tooltip":{ 
 
     "visible":false 
 
     }, 
 
     "z-index":2 
 
    }, 
 
    { 
 
     "values":[ 
 
     15 
 
     ], 
 
     "bar-width":"50%", 
 
     "background-color":"#71cbdc", 
 
     "tooltip":{ 
 
     "visible":false 
 
     }, 
 
     "z-index":2 
 
    }, 
 
    { 
 
     "values":[ 
 
     34 
 
     ], 
 
     "bar-width":"50%", 
 
     "background-color":"#8cc541", 
 
     "tooltip":{ 
 
     "visible":false 
 
     }, 
 
     "z-index":2 
 
    }, 
 
    { 
 
     "values":[ 
 
     14 
 
     ], 
 
     "bar-width":"50%", 
 
     "background-color":"#d96c27", 
 
     "tooltip":{ 
 
     "visible":false 
 
     }, 
 
     "z-index":2 
 
    }, 
 
    { 
 
     "values":[ 
 
     20 
 
     ], 
 
     "bar-width":"50%", 
 
     "background-color":"#ea2629", 
 
     "tooltip":{ 
 
     "visible":false 
 
     }, 
 
     "z-index":2 
 
    } 
 
] 
 
}; 
 

 
zingchart.render({ 
 
\t id: 'myChart', 
 
\t data: myConfig, 
 
\t height: '100%', 
 
\t width: '100%' 
 
});
html, body { 
 
\t height:100%; 
 
\t width:100%; 
 
\t margin:0; 
 
\t padding:0; 
 
} 
 
#myChart { 
 
\t height:100%; 
 
\t width:100%; 
 
\t min-height:150px; 
 
} 
 
.zc-ref { 
 
\t display:none; 
 
}
<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t <!--Assets will be injected here on compile. Use the assets button above--> 
 
\t \t <script src= "https://cdn.zingchart.com/zingchart.min.js"></script> 
 
\t </head> 
 
\t <body> 
 
\t \t <div id="myChart"><a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a></div> 
 
\t </body> 
 
</html>

+0

Если вы попытались эту таблицу, пожалуйста, напишите JSON вы связанный с ним. – nardecky

+0

Я добавил JSON, который я использую в своем оригинальном посте. –

ответ

6

Окончательный образ продукта производится функцией экспорта ZingChart. Просто щелкните правой кнопкой мыши на графике и нажмите View As PNG

enter image description here

Так короткий ответ две вещи:

1) Установите zone этикетки на scale-x и переместить шкалу в противоположную сторону с placement:opposite.

2) Настройте линейную диаграмму над решеткой, чтобы получить свою серой линии.

Преимущества построения линий - это то, что вы можете применить анимацию к линии, если хотите. И если вы хотите снять анимацию, вы тоже можете это сделать. График, как правило, довольно отзывчивый, и это решение, надеюсь, подходит для вашего случая использования.

Линии непосредственно следуют простой формуле, строящей каждое значение линии как [barValue + 2, maxScaleYValue].

Единственный улов здесь в том, что я установил значение max scaleY. Причина, по которой я это сделал, заключается в том, что линия остается неизменной во время изменения размера. Если вы динамически обновляете диаграмму, это не должно быть проблемой, потому что вы также можете обновить значение max scaleY. Просто отсортируйте массив значений бара и выберите максимальное значение + 30. Или какую-нибудь формулу!

Большие изменения, которые я сделал в код были:

  • крючок этикетки на весах
  • скрыть масштаб линий и добавить PlotArea границу
  • участок массив массивов [[]] линейный график
  • настроить свой бар графа должна быть одна серия с нанесенным на нее styles

var maxYValue = 70; 
 
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", 
 
    "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-x-2": { 
 

 
    }, 
 
    "scale-y":{ 
 
"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", 
 
    "borderWidth":1, 
 
    "borderColor":"#ffffff", 
 
    "callout":true, 
 
    "calloutWidth":0, 
 
    "calloutHeight":5, 
 
    'hook': 'scale:name=scale-x,index=0', 
 
    'offset-y': -45, 
 
    "calloutTip":{ 
 
     'offset-y': -35, 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
    } 
 
}, 
 
{ 
 
    "text":"Zone 2", 
 
    "font-size":"13px", 
 
    "borderWidth":1, 
 
    "borderColor":"#ffffff", 
 
    "callout":true, 
 
    "calloutWidth":0, 
 
    "calloutHeight":5, 
 
    'hook': 'scale:name=scale-x,index=1', 
 
    'offset-y': -45, 
 
    "calloutTip":{ 
 
     'offset-y': -35, 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
    } 
 
}, 
 
{ 
 
    "text":"Zone 3", 
 
    "font-size":"13px", 
 
    "borderWidth":1, 
 
    "borderColor":"#ffffff", 
 
    "callout":true, 
 
    "calloutWidth":0, 
 
    "calloutHeight":5, 
 
    'hook': 'scale:name=scale-x,index=2', 
 
    'offset-y': -45, 
 
    "calloutTip":{ 
 
     'offset-y': -35, 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
    } 
 
}, 
 
{ 
 
    "text":"Zone 4", 
 
    "font-size":"13px", 
 
    "borderWidth":1, 
 
    "borderColor":"#ffffff", 
 
    "callout":true, 
 
    "calloutWidth":0, 
 
    "calloutHeight":5, 
 
    'hook': 'scale:name=scale-x,index=3', 
 
    'offset-y': -45, 
 
    "calloutTip":{ 
 
     'offset-y': -35, 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
    } 
 
}, 
 
{ 
 
    "text":"Zone 5", 
 
    "font-size":"13px", 
 
    "borderWidth":1, 
 
    "borderColor":"#ffffff", 
 
    "callout":true, 
 
    "calloutWidth":0, 
 
    "calloutHeight":5, 
 
    'hook': 'scale:name=scale-x,index=4', 
 
    'offset-y': -45, 
 
    "calloutTip":{ 
 
     'offset-y': -35, 
 
     "type":"circle", 
 
     "background-color":"#fff", 
 
     "border-width":2, 
 
     "border-color":"#35353b", 
 
     "size":7, 
 
     "shadow":false 
 
    } 
 
} 
 
    ], 
 
}; 
 

 
zingchart.render({ 
 
id: 'myChart', 
 
data: myConfig, 
 
height: '100%', 
 
width: '100%' 
 
});
html, body { 
 
\t height:100%; 
 
\t width:100%; 
 
\t margin:0; 
 
\t padding:0; 
 
} 
 
#myChart { 
 
\t height:100%; 
 
\t width:100%; 
 
\t min-height:150px; 
 
} 
 
.zc-ref { 
 
\t display:none; 
 
}
<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t <!--Assets will be injected here on compile. Use the assets button above--> 
 
\t \t <script src= 'https://cdn.zingchart.com/zingchart.min.js'></script> 
 

 
\t <!--Inject End--> 
 
\t </head> 
 
\t <body> 
 
\t \t <div id="myChart"><a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a></div> 
 
\t </body> 
 
</html>

+0

По какой-то причине я не смог использовать ваш код «из коробки». Тем не менее, я смог легко настроить его для работы для моих нужд.Спасибо за помощь! –

+0

@ShaynaSymons Меня интересует то, что вам нужно было настроить, чтобы заставить его работать. Это может быть полезно для других, приходящих на этот пост, которые пытаются заставить работать тот же график. – nardecky

Смежные вопросы