简体   繁体   English

使用jquery绘制垂直线

[英]draw vertical lines using jquery

I have the following json and I need to create a grid and also above the grid need to show vertical lines based on the values : 我有以下json,我需要创建一个网格,并且在网格上方需要根据值显示垂直线:

var arr = [];

 arr= [
   {"Measure":"Air Pollution","Rank":"1","Value":"15.5"},
   {"Measure":"Water Pollution","Rank":"2","Value":"13.5"},
   {"Measure":"Soil Erosion","Rank":"3","Value":"10.5"}
 ]

Now I need to create a grid and above the grid, need to create vertical bars based on the "Value". 现在我需要创建一个网格并在网格上方,需要根据“值”创建垂直条。 There will be 3 bars created since there are 3 Values. 由于有3个值,因此将创建3个柱。 Now when 1st row in the grid is selected, the first vertical bar needs to be highlighted . 现在,当选择网格中的第一行时,需要突出显示第一个垂直条。 Similarly, when the 1st vertical bar is selected, the 1st row in the grid to be selected. 类似地,当选择第一垂直条时,要选择网格中的第一行。 Creating the grid is not a problem since I am using KendoUI grid but to create the vertical bars and the selection is the one where I am stuck . 创建网格不是问题,因为我使用KendoUI网格但是创建垂直条并且选择是我被卡住的那个。 Any views ? 任何意见?

Thanks. 谢谢。

I see that you aim to visualize your data as a bar-chart. 我发现您的目标是将数据可视化为条形图。 If so, don't re-invent the wheel. 如果是这样,不要重新发明轮子。 there are a lot of good JS libraries designated for that purpose. 为此目的指定了许多好的JS库。

I've had a good experience using HighCharts , try it out. 我使用HighCharts有很好的经验,试一试。

Disclaimer : This may be an overkill, but is a suited solution should the component be generic (for future compatibility with flexible data) 免责声明 :这可能是一种过度杀伤,但如果组件是通用的(以便与灵活数据的兼容性),这是一个合适的解决方案

Based on @Bogdan M.'s suggestion on using div elements, I've set up a jsFiddle demonstrating vertical bars built using jQuery . 基于@Bogdan M.关于使用div元素的建议,我设置了一个jsFiddle,展示了使用jQuery构建的垂直条 It relays on the input of values as an array of numbers, and converts those to DOM elements, setting their height accordingly. 它将值的输入作为数组转发,并将它们转换为DOM元素,相应地设置它们的高度。

This demo can be very easily updated to use the OP's supplied data structure, and selection behavior functionality can be added as well. 可以非常轻松地更新此演示以使用OP提供的数据结构,并且还可以添加选择行为功能。

This final version (contains the complete solution, both for building the component and for assigning it with selection behavior) can be seen in the full demo on jsFiddle . 最终版本(包含用于构建组件和为其分配选择行为的完整解决方案)可以在jsFiddle的完整演示中看到

All that's left now is to assign handlers for the selection functionality - as cell / row listeners - to the KendoUI grid. 现在剩下的就是将选择功能的处理程序 - 作为单元/行侦听器 - 分配给KendoUI网格。

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

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