D3.js More Free bar chart

Source: Internet
Author: User

One, add a rectangle

//Width and HeightvarW = 500;varH = 100;varDataSet = [5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];//Creating SVG elementsvarSVG = D3.select ("Body"). Append ("SVG"). attr ("Width", W). attr ("Height", h); Svg.selectall ("Rect"). Data (DataSet). Enter (). Append ("Rect"). attr ("X", 0). attr ("Y", 0). attr ("Width", 20). attr ("Height", 100);

Second, add more than one rectangle

//Width and HeightvarW = 500;varH = 100;varDataSet = [5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];//Creating SVG elementsvarSVG = D3.select ("Body"). Append ("SVG"). attr ("Width", W). attr ("Height", h); Svg.selectall ("Rect"). Data (DataSet). Enter (). Append ("Rect"). attr ("X",function(d, i) {returnI * 21;//Bar width of 1 for padding}). attr ("Y", 0). attr ("Width", 20). attr ("Height", 100);

Three, uniform add Bar-the width of the fixed bar

In addition to the way (I * (w/dataset.length);) as the total width of the bar and Gap, when the fixed width of the set is less than the total width, it will naturally generate a blank gap

Bottom Line: The width of the bar is fixed, the total width-Strip width = blank width. Blank width depends on total width, total width depends on calculation expression (w/dataset.length)

//Width and HeightvarW = 500;varH = 100;varbarpadding = 1;varDataSet = [5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];//Creating SVG elementsvarSVG = D3.select ("Body"). Append ("SVG"). attr ("Width", W). attr ("Height", h); Svg.selectall ("Rect"). Data (DataSet). Enter (). Append ("Rect"). attr ("X",function(d, i) {returnI * (w/dataset.length); }). attr ("Y", 0). attr ("Width", 20). attr ("Height", 100);

Four, uniform addition bar-fixed clearance width

Bottom line: The width of the gap is fixed, the total width-blank width = width. Bar width depends on total width (w/dataset.length-barpadding), total width depends on calculation expression (w/dataset.length)

//Width and HeightvarW = 500;varH = 100;varbarpadding = 1;varDataSet = [5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];//Create SVG ElementvarSVG = D3.select ("Body"). Append ("SVG"). attr ("Width", W). attr ("Height", h); Svg.selectall ("Rect"). Data (DataSet). Enter (). Append ("Rect"). attr ("X",function(d, i) {returnI * (w/dataset.length); }). attr ("Y", 0). attr ("width", w/dataset.length-barpadding). attr ("Height", 100);

D3.js More Free bar chart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.