Built with blockbuilder.org
forked from akiraandy's block: fresh block
forked from akiraandy's block: line graph
license: mit |
Built with blockbuilder.org
forked from akiraandy's block: fresh block
forked from akiraandy's block: line graph
date | Value2 | San Francisco | Value | |
---|---|---|---|---|
20111001 | 63.4 | 62.7 | 72.2 | |
20111002 | 58.0 | 59.9 | 67.7 | |
20111003 | 53.3 | 59.1 | -69.4 | |
20111004 | 55.7 | 58.8 | 68.0 | |
20111005 | 64.2 | 58.7 | 72.4 | |
20111006 | 58.8 | 57.0 | 77.0 | |
20111007 | 57.9 | 56.7 | -2.3 | |
20111008 | 61.8 | 56.8 | 78.9 | |
20111009 | 69.3 | 56.7 | 68.8 | |
20111010 | 71.2 | 60.1 | 68.7 | |
20111011 | 68.7 | 61.1 | 70.3 | |
20111012 | 61.8 | 61.5 | 75.3 | |
20111013 | 63.0 | 64.3 | 76.6 | |
20111014 | 66.9 | 67.1 | 66.6 | |
20111015 | 61.7 | 64.6 | 68.0 | |
20111016 | 61.8 | 61.6 | 70.6 | |
20111017 | 62.8 | 61.1 | 71.1 | |
20111018 | 60.8 | 59.2 | 70.0 | |
20111019 | 62.1 | 58.9 | 61.6 | |
20111020 | 65.1 | 57.2 | 57.4 | |
20111021 | 55.6 | 56.4 | 64.3 | |
20111022 | 54.4 | 60.7 | 72.4 | |
20111023 | 54.4 | 65.1 | 72.4 | |
20111024 | 54.8 | 60.9 | 72.5 | |
20111025 | 57.9 | 56.1 | 72.7 | |
20111026 | 54.6 | 54.6 | 73.4 | |
20111027 | 54.4 | 56.1 | 70.7 | |
20111028 | 42.5 | 58.1 | 56.8 | |
20111029 | 40.9 | 57.5 | 51.0 | |
20111030 | 38.6 | 57.7 | 54.9 | |
20111031 | 44.2 | 55.1 | 58.8 | |
20111101 | 49.6 | 57.9 | 62.6 | |
20111102 | 47.2 | 64.6 | 71.0 | |
20111103 | 50.1 | 56.2 | 58.4 | |
20111104 | 50.1 | 50.5 | 45.1 | |
20111105 | 43.5 | 51.3 | 52.2 | |
20111106 | 43.8 | 52.6 | 73.0 | |
20111107 | 48.9 | 51.4 | 75.4 | |
20111108 | 55.5 | 50.6 | 72.1 | |
20111109 | 53.7 | 54.6 | 56.6 | |
20111110 | 57.7 | 55.6 | 55.4 | |
20111111 | 48.5 | 53.9 | 46.7 | |
20111112 | 46.8 | 54.0 | 62.0 | |
20111113 | 51.1 | 53.8 | 71.6 | |
20111114 | 56.8 | 53.5 | 75.5 | |
20111115 | 59.7 | 53.4 | 72.1 | |
20111116 | 56.5 | 52.2 | 65.7 | |
20111117 | 49.6 | 52.7 | 56.8 | |
20111118 | 41.5 | 53.1 | 49.9 | |
20111119 | 44.3 | 49.0 | 71.7 | |
20111120 | 54.0 | 50.4 | 77.7 | |
20111121 | 54.1 | 51.1 | 76.4 | |
20111122 | 49.4 | 52.3 | 68.8 | |
20111123 | 50.0 | 54.6 | 57.0 | |
20111124 | 44.0 | 55.1 | 55.5 | |
20111125 | 50.3 | 51.5 | 61.6 | |
20111126 | 52.1 | 53.6 | 64.1 | |
20111127 | 49.6 | 52.3 | 51.1 | |
20111128 | 57.2 | 51.0 | 43.0 | |
20111129 | 59.1 | 49.5 | 46.4 | |
20111130 | 50.6 | 49.8 | 48.0 | |
20111201 | 44.3 | 60.4 | 48.1 | |
20111202 | 43.9 | 62.2 | 60.6 | |
20111203 | 42.1 | 58.3 | 62.6 | |
20111204 | 43.9 | 52.7 | 57.1 | |
20111205 | 50.2 | 51.5 | 44.2 | |
20111206 | 54.2 | 49.9 | 37.4 | |
20111207 | 54.6 | 48.6 | 35.0 | |
20111208 | 43.4 | 46.4 | 37.0 | |
20111209 | 42.2 | 49.8 | 45.4 | |
20111210 | 45.0 | 52.1 | 50.7 | |
20111211 | 33.8 | 48.8 | 48.6 | |
20111212 | 36.8 | 47.4 | 52.2 | |
20111213 | 38.6 | 47.2 | 60.8 | |
20111214 | 41.9 | 46.1 | 70.0 | |
20111215 | 49.6 | 48.8 | 64.2 | |
20111216 | 50.2 | 47.9 | 50.9 | |
20111217 | 40.6 | 49.8 | 51.6 | |
20111218 | 29.1 | 49.1 | 55.2 | |
20111219 | 33.7 | 48.3 | 62.1 | |
20111220 | 45.8 | 49.3 | 56.3 | |
20111221 | 47.4 | 48.4 | 47.2 | |
20111222 | 54.4 | 53.3 | 52.3 | |
20111223 | 47.8 | 47.5 | 45.2 | |
20111224 | 34.9 | 47.9 | 43.6 | |
20111225 | 35.9 | 48.9 | 42.9 | |
20111226 | 43.6 | 45.9 | 48.2 | |
20111227 | 42.9 | 47.2 | 45.4 | |
20111228 | 46.2 | 48.9 | 44.2 | |
20111229 | 30.8 | 50.9 | 50.4 | |
20111230 | 40.8 | 52.9 | 52.4 | |
20111231 | 49.8 | 50.1 | -53.5 | |
20120101 | 46.3 | 53.9 | 55.9 | |
20120102 | 43.2 | 53.1 | 48.2 | |
20120103 | 30.3 | 49.7 | 41.0 | |
20120104 | 19.2 | 52.7 | 48.9 | |
20120105 | 32.1 | 52.6 | 54.8 | |
20120106 | 41.2 | 49.0 | 61.2 | |
20120107 | 47.0 | 51.0 | 59.7 | |
20120108 | 46.0 | 56.8 | 52.5 | |
20120109 | 34.7 | 52.3 | 54.0 | |
20120110 | 39.4 | 51.6 | 47.7 | |
20120111 | 40.4 | 49.8 | 49.2 | |
20120112 | 45.4 | 51.9 | 48.4 | |
20120113 | 40.7 | 53.7 | 40.2 | |
20120114 | 30.4 | 52.9 | 43.9 | |
20120115 | 23.9 | 49.7 | 45.2 | |
20120116 | 22.6 | 45.3 | 65.0 | |
20120117 | 39.8 | 43.6 | 68.2 | |
20120118 | 43.2 | 45.0 | 47.5 | |
20120119 | 26.3 | 47.3 | 57.1 | |
20120120 | 32.8 | 51.4 | 61.9 | |
20120121 | 27.4 | 53.7 | 54.6 | |
20120122 | 25.0 | 48.3 | 56.7 | |
20120123 | 39.4 | 52.9 | 54.4 | |
20120124 | 48.7 | 49.1 | 52.7 | |
20120125 | 43.0 | 52.1 | 61.8 | |
20120126 | 37.1 | 53.6 | 55.0 | |
20120127 | 48.2 | 50.4 | 50.7 | |
20120128 | 43.7 | 50.3 | 52.9 | |
20120129 | 40.1 | 53.8 | 44.4 | |
20120130 | 38.0 | 51.9 | 49.1 | |
20120131 | 43.5 | 50.0 | 62.8 | |
20120201 | 50.4 | 50.0 | 64.6 | |
20120202 | 45.8 | 51.3 | 61.1 | |
20120203 | 37.5 | 51.5 | 70.0 | |
20120204 | 40.8 | 52.0 | 61.3 | |
20120205 | 36.5 | 53.8 | 48.2 | |
20120206 | 39.1 | 54.6 | 44.2 | |
20120207 | 43.2 | 54.3 | 51.3 | |
20120208 | 36.5 | 51.9 | 49.2 | |
20120209 | 36.5 | 53.8 | 45.7 | |
20120210 | 38.3 | 53.9 | 54.1 | |
20120211 | 36.9 | 52.3 | 44.9 | |
20120212 | 29.7 | 50.1 | 36.5 | |
20120213 | 33.1 | 49.5 | 44.8 | |
20120214 | 39.6 | 48.6 | 52.3 | |
20120215 | 42.3 | 49.9 | 68.0 | |
20120216 | 39.7 | 52.4 | 54.6 | |
20120217 | 46.0 | 49.9 | 53.8 | |
20120218 | 41.2 | 51.6 | 56.2 | |
20120219 | 39.8 | 47.8 | 50.8 | |
20120220 | 38.1 | 48.7 | 53.0 | |
20120221 | 37.1 | 49.7 | 61.0 | |
20120222 | 45.5 | 53.4 | 68.8 | |
20120223 | 50.6 | 54.1 | 69.4 | |
20120224 | 42.7 | 55.9 | 59.3 | |
20120225 | 42.6 | 51.7 | 47.2 | |
20120226 | 36.9 | 47.7 | 47.7 | |
20120227 | 40.9 | 45.4 | 61.9 | |
20120228 | 45.9 | 47.0 | 67.2 | |
20120229 | 40.7 | 49.8 | 70.1 | |
20120301 | 41.3 | 48.9 | 62.1 | |
20120302 | 36.8 | 48.1 | 72.7 | |
20120303 | 47.6 | 50.7 | 59.0 | |
20120304 | 44.2 | 55.0 | 51.8 | |
20120305 | 38.5 | 48.8 | 55.0 | |
20120306 | 32.9 | 48.4 | 61.8 | |
20120307 | 43.3 | 49.9 | 67.1 | |
20120308 | 51.2 | 49.2 | 72.0 | |
20120309 | 47.8 | 51.7 | 46.4 | |
20120310 | 37.2 | 49.3 | 46.7 | |
20120311 | 42.9 | 50.0 | 56.9 | |
20120312 | 48.8 | 48.6 | 61.9 | |
20120313 | 52.6 | 53.9 | 68.8 | |
20120314 | 60.5 | 55.2 | 71.9 | |
20120315 | 47.2 | 55.9 | 72.0 | |
20120316 | 44.7 | 54.6 | 72.5 | |
20120317 | 48.2 | 48.2 | 71.7 | |
20120318 | 48.2 | 47.1 | -71.1 | |
20120319 | 53.1 | 45.8 | 73.0 | |
20120320 | 57.8 | 49.7 | 63.8 | |
20120321 | 57.5 | 51.4 | 60.0 | |
20120322 | 57.3 | 51.4 | 62.3 | |
20120323 | 61.7 | 48.4 | 61.1 | |
20120324 | 55.8 | 49.0 | 62.0 | |
20120325 | 48.4 | 46.4 | 64.6 | |
20120326 | 49.8 | 49.7 | 66.0 | |
20120327 | 39.6 | 54.1 | 65.8 | |
20120328 | 49.7 | 54.6 | 69.2 | |
20120329 | 56.8 | 52.3 | 69.5 | |
20120330 | 46.5 | 54.5 | 73.5 | |
20120331 | 42.2 | 56.2 | 73.9 | |
20120401 | 45.3 | 51.1 | 75.3 | |
20120402 | 48.1 | 50.5 | 75.4 | |
20120403 | 51.2 | 52.2 | 77.3 | |
20120404 | 61.0 | 50.6 | 67.0 | |
20120405 | 50.7 | 47.9 | 71.1 | |
20120406 | 48.0 | 47.4 | 70.4 | |
20120407 | 51.1 | 49.4 | 73.6 | |
20120408 | 55.7 | 50.0 | 71.1 | |
20120409 | 58.3 | 51.3 | 70.0 | |
20120410 | 55.0 | 53.8 | 69.0 | |
20120411 | 49.0 | 52.9 | 69.2 | |
20120412 | 51.7 | 53.9 | 74.5 | |
20120413 | 53.1 | 50.2 | 73.4 | |
20120414 | 55.2 | 50.9 | 76.0 | |
20120415 | 62.3 | 51.5 | 74.5 | |
20120416 | 62.9 | 51.9 | 63.6 | |
20120417 | 69.3 | 53.2 | 67.3 | |
20120418 | 59.0 | 53.0 | 65.1 | |
20120419 | 54.1 | 55.1 | 67.9 | |
20120420 | 56.5 | 55.8 | 68.9 | |
20120421 | 58.2 | 58.0 | 65.1 | |
20120422 | 52.4 | 52.8 | 65.4 | |
20120423 | 51.6 | 55.1 | 70.1 | |
20120424 | 49.3 | 57.9 | -67.0 | |
20120425 | 52.5 | 57.5 | 75.4 | |
20120426 | 50.5 | 55.3 | 77.5 | |
20120427 | 51.9 | 53.5 | 77.0 | |
20120428 | 47.4 | 54.7 | 77.7 | |
20120429 | 54.1 | 54.0 | 77.7 | |
20120430 | 51.9 | 53.4 | 77.7 | |
20120501 | 57.4 | 52.7 | 77.0 | |
20120502 | 53.7 | 50.7 | 77.9 | |
20120503 | 53.1 | 52.6 | 79.1 | |
20120504 | 57.2 | 53.4 | 80.1 | |
20120505 | 57.0 | 53.1 | 82.1 | |
20120506 | 56.6 | 56.5 | 79.0 | |
20120507 | 54.6 | 55.3 | 79.8 | |
20120508 | 57.9 | 52.0 | 70.0 | |
20120509 | 59.2 | 52.4 | 69.8 | |
20120510 | 61.1 | 53.4 | 71.3 | |
20120511 | 59.7 | 53.1 | 69.4 | |
20120512 | 64.1 | 49.9 | 72.0 | |
20120513 | 65.3 | 52.0 | 72.4 | |
20120514 | 64.2 | 56.0 | 72.5 | |
20120515 | 62.0 | 53.0 | 67.6 | |
20120516 | 63.8 | 51.0 | 69.0 | |
20120517 | 64.5 | 51.4 | 72.7 | |
20120518 | 61.0 | 52.2 | 73.7 | |
20120519 | 62.6 | 52.4 | 77.5 | |
20120520 | 66.2 | 54.5 | 75.8 | |
20120521 | 62.7 | 52.8 | 76.9 | |
20120522 | 63.7 | 53.9 | 78.8 | |
20120523 | 66.4 | 56.5 | 77.7 | |
20120524 | 64.5 | 54.7 | 80.6 | |
20120525 | 65.4 | 52.5 | 81.4 | |
20120526 | 69.4 | 52.1 | 82.3 | |
20120527 | 71.9 | 52.2 | 80.3 | |
20120528 | 74.4 | 52.9 | 80.3 | |
20120529 | 75.9 | 52.1 | 82.2 | |
20120530 | 72.9 | 52.1 | 81.9 | |
20120531 | 72.5 | 53.3 | 82.4 | |
20120601 | 67.2 | 54.8 | 77.9 | |
20120602 | 68.3 | 54.0 | 81.1 | |
20120603 | 67.7 | 52.3 | 82.2 | |
20120604 | 61.9 | 55.3 | 81.2 | |
20120605 | 58.3 | 53.5 | 83.0 | |
20120606 | 61.7 | 54.1 | 83.2 | |
20120607 | 66.7 | 53.9 | 82.1 | |
20120608 | 68.7 | 54.4 | 77.5 | |
20120609 | 72.2 | 55.0 | 77.9 | |
20120610 | 72.6 | 60.0 | 82.9 | |
20120611 | 69.2 | 57.2 | 86.8 | |
20120612 | 66.9 | 55.1 | 85.3 | |
20120613 | 66.7 | 53.3 | 76.9 | |
20120614 | 67.7 | 53.4 | 84.5 | |
20120615 | 68.5 | 54.6 | 84.4 | |
20120616 | 67.5 | 57.0 | -83.8 | |
20120617 | 64.2 | 55.6 | 82.5 | |
20120618 | 61.7 | 52.5 | 82.9 | |
20120619 | 66.4 | 53.9 | 82.5 | |
20120620 | 77.9 | 55.3 | 81.3 | |
20120621 | 88.3 | 53.3 | 80.8 | |
20120622 | 82.2 | 54.1 | 81.7 | |
20120623 | 77.0 | 55.2 | 83.9 | |
20120624 | 75.4 | 55.8 | 85.5 | |
20120625 | 70.9 | 56.8 | 87.2 | |
20120626 | 65.9 | 57.5 | 88.0 | |
20120627 | 73.5 | 57.7 | 89.6 | |
20120628 | 77.4 | 56.6 | 86.7 | |
20120629 | 79.6 | 56.4 | 85.3 | |
20120630 | 84.2 | 58.4 | 81.7 | |
20120701 | 81.8 | 58.8 | 78.5 | |
20120702 | 82.5 | 56.4 | 83.1 | |
20120703 | 80.2 | 56.5 | 83.1 | |
20120704 | 77.8 | 55.8 | 84.5 | |
20120705 | 86.1 | 54.8 | 84.6 | |
20120706 | 79.9 | 54.9 | 84.2 | |
20120707 | 83.5 | 54.7 | 86.7 | |
20120708 | 81.5 | 52.8 | 84.3 | |
20120709 | 77.8 | 53.7 | 83.7 | |
20120710 | 76.1 | 53.1 | 77.1 | |
20120711 | 76.3 | 52.7 | 77.4 | |
20120712 | 75.8 | 52.0 | 80.6 | |
20120713 | 77.2 | 53.4 | 81.4 | |
20120714 | 79.3 | 54.0 | 80.2 | |
20120715 | 78.9 | 54.0 | 81.8 | |
20120716 | 79.6 | 54.5 | 77.3 | |
20120717 | 83.3 | 56.7 | 80.8 | |
20120718 | 84.3 | 57.5 | 81.6 | |
20120719 | 75.1 | 57.1 | 80.9 | |
20120720 | 68.4 | 58.1 | 83.9 | |
20120721 | 68.4 | 57.6 | 85.6 | |
20120722 | 72.2 | 56.0 | 83.6 | |
20120723 | 75.6 | 56.6 | 84.0 | |
20120724 | 82.6 | 57.8 | 83.0 | |
20120725 | 78.4 | 57.5 | 84.8 | |
20120726 | 77.0 | 56.4 | 84.4 | |
20120727 | 79.4 | 55.3 | 84.3 | |
20120728 | 77.4 | 55.0 | 83.9 | |
20120729 | 72.5 | 55.6 | 85.0 | |
20120730 | 72.9 | 55.6 | 84.9 | |
20120731 | 73.6 | 55.9 | 86.3 | |
20120801 | 75.0 | 55.4 | 86.5 | |
20120802 | 77.7 | 54.4 | 85.8 | |
20120803 | 79.7 | 53.7 | 85.3 | |
20120804 | 79.6 | 54.1 | 86.0 | |
20120805 | 81.5 | 57.8 | 84.2 | |
20120806 | 80.0 | 58.2 | 81.9 | |
20120807 | 75.7 | 58.0 | 86.5 | |
20120808 | 77.8 | 57.0 | 86.1 | |
20120809 | 78.6 | 55.0 | 86.8 | |
20120810 | 77.8 | 54.8 | 88.0 | |
20120811 | 78.5 | 53.0 | 85.1 | |
20120812 | 78.8 | 52.5 | 87.4 | |
20120813 | 78.6 | 53.3 | 88.0 | |
20120814 | 76.8 | 53.9 | 88.0 | |
20120815 | 76.7 | 56.2 | 87.2 | |
20120816 | 75.9 | 57.1 | 86.1 | |
20120817 | 77.6 | 55.3 | 86.8 | |
20120818 | 72.6 | 56.2 | 84.9 | |
20120819 | 70.4 | 54.3 | 76.8 | |
20120820 | 71.8 | 53.1 | 80.6 | |
20120821 | 73.6 | 53.4 | 80.0 | |
20120822 | 74.7 | 54.5 | 78.2 | |
20120823 | 74.6 | 55.7 | 79.1 | |
20120824 | 76.0 | 54.8 | 81.9 | |
20120825 | 76.2 | 53.8 | 84.7 | |
20120826 | 73.4 | 56.5 | 83.5 | |
20120827 | 74.6 | 58.3 | 82.1 | |
20120828 | 79.4 | 58.7 | 84.0 | |
20120829 | 74.7 | 57.5 | 85.7 | |
20120830 | 73.5 | 55.9 | 87.2 | |
20120831 | 77.9 | 55.4 | 82.9 | |
20120901 | 80.7 | 55.7 | 84.8 | |
20120902 | 75.1 | 53.1 | 83.9 | |
20120903 | 73.5 | 53.5 | 85.5 | |
20120904 | 73.5 | 52.5 | 86.4 | |
20120905 | 77.7 | 54.5 | 85.8 | |
20120906 | 74.2 | 56.3 | 85.4 | |
20120907 | 76.0 | 56.4 | 85.3 | |
20120908 | 77.1 | 56.5 | 81.9 | |
20120909 | 69.7 | 56.4 | 74.8 | |
20120910 | 67.8 | 55.4 | 71.6 | |
20120911 | 64.0 | 56.2 | 75.9 | |
20120912 | 68.1 | 55.7 | 82.1 | |
20120913 | 69.3 | 54.3 | 80.5 | |
20120914 | 70.0 | 55.2 | 70.0 | |
20120915 | 69.3 | 54.3 | 71.2 | |
20120916 | 66.3 | 52.9 | 70.3 | |
20120917 | 67.0 | 54.8 | 72.1 | |
20120918 | 72.8 | 54.8 | 73.7 | |
20120919 | 67.2 | 56.8 | 72.7 | |
20120920 | 62.1 | 55.4 | 71.7 | |
20120921 | 64.0 | 55.8 | 72.9 | |
20120922 | 65.5 | 55.9 | 73.1 | |
20120923 | 65.7 | 52.8 | 75.6 | |
20120924 | 60.4 | 54.5 | 78.3 | |
20120925 | 63.2 | 53.3 | 78.3 | |
20120926 | 68.5 | 53.6 | 79.6 | |
20120927 | 69.2 | 52.1 | 76.4 | |
20120928 | 68.7 | 52.6 | 77.2 | |
20120929 | 62.5 | 53.9 | 75.2 | |
20120930 | 62.3 | 55.1 | 71.9 |
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<!-- <svg></svg> --> | |
<div id='div1' style="background:beige"></div> | |
<div id='div2' style="background:bisque"></div> | |
<div id='div3' style="background:beige"></div> | |
<script> | |
function linegraph(data,divid,xaxisformat){ | |
//console.log(data); | |
var margin = {top: 20, bottom: 60, left: 40, right: 20}; | |
var width = 400 | |
var height = 300; | |
var dotRadius = 2; | |
hoverTransition = d3.transition() | |
.ease(d3.easeLinear); | |
d3.select( divid+"svg").remove(); | |
var svg = d3.select(divid).append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.attr("id", divid+ "svg"); | |
//y label | |
svg.append("g") | |
.attr("class", "y label") | |
.append("text") | |
.text("Chlorophyll Concentration ($)") | |
.attr("transform", "rotate(-90)") | |
.attr("y", 0 ) | |
.attr("x", -((height+ margin.top + margin.bottom+80) / 2)) | |
.attr("dy", ".71em"); | |
// scales | |
var xExtent = d3.extent(data, d => d.date); | |
var xScale = d3.scaleTime() | |
.domain(xExtent) | |
.range([margin.left, width - margin.right]); | |
var yExtent = d3.extent(data, d => d.Value); | |
var yScale = d3.scaleLinear() | |
.domain(yExtent) | |
.range([height - margin.bottom, margin.top]); | |
var xAxis = d3.axisBottom() | |
.scale(xScale) | |
.tickFormat(d3.timeFormat(xaxisformat)) | |
.ticks(15); | |
var yAxis = d3.axisLeft() | |
.scale(yScale); | |
var line = d3.line() | |
.defined(function(d) { return d.Value }) | |
.x((d) => { return xScale(d.date); }) | |
.y((d) => { return yScale(d.Value);}); | |
svg.append('path') | |
.attr('fill', 'none') | |
.attr('stroke', 'green') | |
.attr('d', line(data)); | |
svg.append('g') | |
.attr('transform', 'translate(' + [0, height-margin.bottom] + ')') | |
.call(xAxis) | |
.selectAll("text") | |
.attr("y", 0) | |
.attr("x", 9) | |
.attr("dy", ".35em") | |
.attr("transform", "rotate(90)") | |
.style("text-anchor", "start");; | |
svg.append('g') | |
.attr('transform', 'translate(' + [margin.left, 0] +')') | |
.call(yAxis); | |
dots = svg.append('g') | |
.selectAll('circle') | |
.data(data) | |
.enter().append('circle') | |
.attr('cx', d => xScale(d.date)) | |
.attr('cy', function(d){ if(d.Value) return yScale(d.Value); }) | |
.attr('r', dotRadius) | |
.attr('fill', 'salmon') | |
.attr('stroke', 'white') | |
.attr('opacity',function(d){ if(d.Value) return 1; | |
else return 0;}) | |
.attr('stroke-width', 1) | |
.style('cursor', 'pointer') | |
.on('mouseenter', function() { | |
d3.select(this) | |
.interrupt() | |
.transition(hoverTransition) | |
.duration(300) | |
.attr('r', dotRadius * 2); | |
}) | |
.on('mouseleave', function() { | |
d3.select(this) | |
.interrupt() | |
.transition(hoverTransition) | |
.duration(300) | |
.attr('r', dotRadius); | |
}); | |
}// function linegraph ends | |
function linegraph_m(data1, data2,divid,xaxisformat){ | |
//console.log(data); | |
var margin = {top: 20, bottom: 60, left: 40, right: 20}; | |
var width = 400 | |
var height = 300; | |
var dotRadius = 2; | |
hoverTransition = d3.transition() | |
.ease(d3.easeLinear); | |
d3.select( "#svg"+ divid.substring(1,divid.length-1)).remove(); | |
var svg = d3.select(divid).append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.attr("id", "svg" + divid.substring(1,divid.length-1)); | |
//y label | |
svg.append("g") | |
.attr("class", "y label") | |
.append("text") | |
.text("Chlorophyll Concentration ($)") | |
.attr("transform", "rotate(-90)") | |
.attr("y", 0 ) | |
.attr("x", -((height+ margin.top + margin.bottom+80) / 2)) | |
.attr("dy", ".71em"); | |
// scales | |
var xExtent = d3.extent(data1, d => d.date); | |
var xScale = d3.scaleTime() | |
.domain(xExtent) | |
.range([margin.left, width - margin.right]); | |
var y1Extent = d3.extent(data1, d => d.Value); | |
var y2Extent = d3.extent(data2, d => d.Value); | |
var y1min= y1Extent['0']; var y1max = y1Extent['1']; | |
var y2min= y2Extent['0']; var y2max = y2Extent['1']; | |
var ymin = y1min<y2min? y1min:y2min; | |
var ymax = y1max>y2max? y1max:y2max; | |
var yExtent = [ymin,ymax]; | |
var yScale = d3.scaleLinear() | |
.domain(yExtent) | |
.range([height - margin.bottom, margin.top]); | |
var xAxis = d3.axisBottom() | |
.scale(xScale) | |
.tickFormat(d3.timeFormat(xaxisformat)) | |
.ticks(10); | |
var yAxis = d3.axisLeft() | |
.scale(yScale); | |
var line = d3.line() | |
.defined(function(d) { return d.Value }) | |
.x((d) => { return xScale(d.date); }) | |
.y((d) => { return yScale(d.Value);}); | |
var line2 = d3.line() | |
.defined(function(d) { return d.Value }) | |
.x((d) => { return xScale(d.date); }) | |
.y((d) => { return yScale(d.Value);}); | |
svg.append('path') | |
.attr('fill', 'none') | |
.attr('stroke', 'green') | |
.attr('d', line(data1)); | |
svg.append('path') | |
.attr('fill', 'none') | |
.attr('stroke', 'red') | |
.attr('d', line(data2)); | |
svg.append('g') | |
.attr('transform', 'translate(' + [0, height-margin.bottom] + ')') | |
.call(xAxis) | |
.selectAll("text") | |
.attr("y", 0) | |
.attr("x", 9) | |
.attr("dy", ".35em") | |
.attr("transform", "rotate(90)") | |
.style("text-anchor", "start");; | |
svg.append('g') | |
.attr('transform', 'translate(' + [margin.left, 0] +')') | |
.call(yAxis); | |
//graph legends | |
svg.append("g") | |
.append("text") | |
.attr("x", width - width/5) | |
.attr("y", 20) | |
.style("font-size","20px") | |
.style("font-weight","bold") | |
.style("fill","green") | |
.text("Winter") | |
svg.append("g") | |
.append("text") | |
.attr("x", width - width/5) | |
.attr("y", 40) | |
.style("font-size","20px") | |
.style("font-weight","bold") | |
.style("fill","red") | |
.text("Summer") | |
}// function linegraph_m ends | |
var datas=[];var datas2=[]; | |
d3.tsv('data.tsv', (err, data) => { | |
var city = 'San Francisco'; | |
// clean the data | |
data.forEach(d => { | |
d.date = d3.timeParse("%Y%m%d")(d.date); | |
d.date = new Date(d.date); // x | |
d.Value= ++d.Value; // y | |
var t = []; | |
t['date']= d.date;t['Value']= d.Value; | |
datas.push(t) | |
var t2 = []; | |
t2['date']= d.date;t2['Value']= d.Value2; | |
datas2.push(t2) | |
; | |
}); | |
//linegraph(datas,'#div1'); | |
//linegraph(datas2,'#div2'); | |
//linegraph_m(datas,datas2,'#div1'); | |
}); | |
var data3= {"20010701":0.62988,"20020701":1.0145,"20050701":0.93277,"20021001":1.1886,"20141001":0.5987,"20100101":0.63705,"19990201":0.41373,"19991001":0.65843,"20080401":1.4093,"20070501":1.3278,"20160301":0.23324,"20100901":1.1682,"20060301":1.5995,"20030701":0.82621,"20150801":0.32226,"20120401":0.45349,"20150201":0.29297,"20160901":0.37223,"20140101":0.40749,"20090101":0.94806,"20081001":1.3486,"20040801":0.67657,"20050201":0.56134,"20120601":0.32884,"20120801":0.38043,"20040901":1.0534,"20080801":1.2879,"20050301":0.75237,"20000301":0.44091,"20060901":0.7975,"20010401":0.23005,"20061001":2.1458,"20020201":0.48023,"20070101":0.6456,"20081101":1.241,"20130701":0.44937,"20100501":1.0526,"20110501":1.6146,"20000701":0.51482,"20110901":1.2715,"20090401":0.98868,"20150601":0.21784,"20080201":0.53343,"20110601":0.85397,"20151101":0.69967,"19990801":0.48882,"20160101":0.40975,"19980401":0.26156,"20130901":0.45541,"20140201":0.36124,"20091101":1.0836,"20020501":0.66316,"20040701":1.0683,"20121201":0.70251,"20021101":0.9007,"20010801":0.79442,"19991101":0.64762,"20080701":0.78111,"20070201":0.48197,"20090701":0.82996,"20131001":0.74442,"20040301":0.46763,"20090601":1.0697,"20160401":0.2877,"20110201":0.89083,"20160701":0.33033,"20071101":0.98552,"20030401":0.70403,"20060201":1.1944,"20150101":0.3747,"20141101":0.62175,"20070801":0.7464,"20140601":0.26027,"20051201":0.77159,"20101201":1.3108,"20100601":0.88399,"20001001":0.56191,"19981201":0.5181,"20020801":0.76278,"20001101":0.5473,"20041001":1.0764,"19990401":0.27083,"20120101":0.7991,"20000201":0.39761,"20080101":0.60427,"20141201":0.56689,"20060801":1.1996,"19990101":0.36933,"20030601":0.85429,"20140901":0.43865,"20111101":1.0465,"20130601":0.3919,"20150501":0.34517,"20000601":0.46939,"20080501":0.80937,"20061101":1.0325,"20020901":0.91199,"20050401":0.68882,"20031201":0.66448,"20100201":0.89335,"20030801":0.75114,"20030101":0.6494,"20011201":0.49032,"19980501":0.23936,"20130801":0.46747,"20070601":0.92839,"20140301":0.34761,"20070701":1.179,"20001201":0.37633,"20040601":0.78044,"20121101":0.58443,"20050801":0.93772,"19990601":0.27338,"20060501":0.86542,"19981101":0.36481,"20000101":0.33369,"20130301":0.26159,"20161201":0.4865,"19991201":0.4679,"20101101":1.0892,"20010901":0.76786,"20121001":0.406,"20080601":0.95128,"20081201":0.70217,"20131101":0.62508,"20110101":0.75296,"20040201":0.6555,"20160501":0.23852,"20000901":0.42194,"20071001":1.1461,"20060101":0.6214,"20030501":0.89609,"19971001":0.35247,"20110701":0.918,"20010101":0.4556,"20150901":0.35319,"20031101":0.86856,"20140701":0.37077,"20100701":1.3391,"20140401":0.17361,"20020601":0.72445,"19980801":0.55826,"20041101":0.76683,"20130501":0.34998,"20120201":0.95702,"20000501":0.25264,"20120901":0.44554,"20090201":0.45535,"20040501":1.0599,"20070901":0.84594,"20100401":1.7412,"20120501":0.49179,"20111001":1.0814,"20030201":0.88965,"19980601":0.40242,"20060701":0.79007,"20111201":0.95613,"20130101":0.48137,"20120701":0.43888,"20061201":0.87708,"20150401":0.36323,"19980101":0.35378,"20010501":0.21493,"20020101":0.55178,"20110401":1.0271,"20050501":0.81149,"19970901":0.25734,"20100301":0.90294,"20011101":0.74426,"20030901":1.0735,"20090501":0.94207,"20011001":0.68135,"19971201":0.33033,"20151201":0.59147,"20070401":0.96226,"20131201":0.64842,"19990501":0.2753,"20040101":0.63859,"20070301":0.84366,"20160201":0.37313,"20041201":0.75956,"20020401":0.49708,"20100801":1.2854,"20110801":1.1116,"20060601":1.002,"20091001":1.3706,"20150301":0.37182,"20130201":0.25924,"20071201":0.86397,"20050901":1.1063,"20101001":1.8429,"20140801":0.42949,"19981001":0.61196,"20060401":1.3244,"20160601":0.21011,"19980301":0.35274,"20161001":0.51393,"20050101":0.51313,"20021201":0.91644,"20080901":1.0959,"20000801":0.52909,"20150701":0.35266,"20010201":0.54627,"19971101":0.44068,"20090801":0.99253,"20010301":0.38897,"20020301":0.40077,"20090901":1.272,"20140501":0.30664,"19990301":0.32336,"20010601":0.47414,"19980901":0.35407,"20130401":0.38955,"20120301":0.67816,"20000401":0.26447,"20080301":1.5156,"20090301":0.5079,"20151001":0.51433,"20040401":0.96713,"20031001":1.5892,"19990901":0.4748,"19980201":0.19746,"20030301":0.61348,"19990701":0.53275,"19980701":0.40322,"20091201":1.1951,"20051001":0.89727,"20051101":1.0736,"20161101":0.62355,"20110301":0.86496,"20050601":0.70223,"20160801":0.33012}; | |
var data4={"20010701":0.38609,"20020701":0.47014,"20050701":0.38045,"20021001":NaN,"20141001":NaN,"20100101":NaN,"19990201":0.25135,"19991001":0.50149,"20080401":NaN,"20070501":NaN,"20160301":NaN,"20100901":NaN,"20060301":0.19371,"20030701":0.31628,"20150801":NaN,"20120401":NaN,"20150201":NaN,"20160901":NaN,"20140101":NaN,"20090101":0.23835,"20081001":NaN,"20040801":0.27702,"20050201":0.23618,"20120601":NaN,"20120801":NaN,"20040901":0.35923,"20080801":NaN,"20050301":NaN,"20000301":0.29986,"20060901":0.41712,"20010401":0.26299,"20061001":0.53065,"20020201":0.27056,"20070101":0.35718,"20081101":NaN,"20130701":NaN,"20100501":NaN,"20110501":NaN,"20000701":0.32906,"20110901":NaN,"20090401":NaN,"20150601":NaN,"20080201":NaN,"20110601":NaN,"20151101":NaN,"19990801":0.2665,"20160101":NaN,"19980401":NaN,"20130901":NaN,"20140201":NaN,"20091101":NaN,"20020501":0.18445,"20040701":0.20331,"20121201":NaN,"20021101":0.44877,"20010801":0.50693,"19991101":0.42636,"20080701":NaN,"20070201":0.28398,"20090701":NaN,"20131001":NaN,"20040301":0.23219,"20090601":0.25161,"20160401":NaN,"20110201":NaN,"20160701":NaN,"20071101":0.42599,"20030401":0.15911,"20060201":0.27327,"20150101":NaN,"20141101":NaN,"20070801":NaN,"20140601":NaN,"20051201":0.45325,"20101201":NaN,"20100601":NaN,"20001001":0.47459,"19981201":0.41694,"20020801":0.25864,"20001101":0.62489,"20041001":0.3725,"19990401":0.075639,"20120101":NaN,"20000201":0.23222,"20080101":NaN,"20141201":NaN,"20060801":0.35791,"19990101":0.25155,"20030601":0.2351,"20140901":NaN,"20111101":NaN,"20130601":NaN,"20150501":NaN,"20000601":0.23753,"20080501":NaN,"20061101":0.58047,"20020901":0.77895,"20050401":0.27251,"20031201":0.31269,"20100201":NaN,"20030801":0.3145,"20030101":0.3213,"20011201":0.40763,"19980501":NaN,"20130801":NaN,"20070601":NaN,"20140301":NaN,"20070701":NaN,"20001201":0.25659,"20040601":0.13841,"20121101":NaN,"20050801":0.49893,"19990601":0.13843,"20060501":0.25818,"19981101":NaN,"20000101":0.25189,"20130301":NaN,"20161201":NaN,"19991201":0.37847,"20101101":NaN,"20010901":0.40811,"20121001":NaN,"20080601":NaN,"20081201":NaN,"20131101":NaN,"20110101":NaN,"20040201":NaN,"20160501":NaN,"20000901":0.3266,"20071001":0.54247,"20060101":0.39355,"20030501":0.24915,"19971001":NaN,"20110701":NaN,"20010101":0.29259,"20150901":NaN,"20031101":0.61568,"20140701":NaN,"20100701":NaN,"20140401":NaN,"20020601":0.25147,"19980801":NaN,"20041101":0.49676,"20130501":NaN,"20120201":NaN,"20000501":0.15193,"20120901":NaN,"20090201":0.19792,"20040501":0.26892,"20070901":0.30579,"20100401":NaN,"20120501":NaN,"20111001":NaN,"20030201":0.2693,"19980601":0.165,"20060701":0.32316,"20111201":NaN,"20130101":NaN,"20120701":NaN,"20061201":0.41057,"20150401":NaN,"19980101":0.23646,"20010501":0.21799,"20020101":0.48025,"20110401":NaN,"20050501":0.26419,"19970901":NaN,"20100301":NaN,"20011101":0.49625,"20030901":0.45066,"20090501":NaN,"20011001":0.65259,"19971201":0.28335,"20151201":NaN,"20070401":NaN,"20131201":NaN,"19990501":0.25894,"20040101":0.34004,"20070301":0.20001,"20160201":NaN,"20041201":0.47017,"20020401":0.21882,"20100801":NaN,"20110801":NaN,"20060601":NaN,"20091001":NaN,"20150301":NaN,"20130201":NaN,"20071201":0.5173,"20050901":0.40748,"20101001":NaN,"20140801":NaN,"19981001":0.48725,"20060401":NaN,"20160601":NaN,"19980301":0.21096,"20161001":NaN,"20050101":0.34225,"20021201":0.34558,"20080901":NaN,"20000801":0.28339,"20150701":NaN,"20010201":0.20954,"19971101":0.47232,"20090801":NaN,"20010301":0.29859,"20020301":0.26216,"20090901":NaN,"20140501":NaN,"19990301":0.25478,"20010601":0.2854,"19980901":0.27673,"20130401":NaN,"20120301":NaN,"20000401":0.14137,"20080301":NaN,"20090301":NaN,"20151001":NaN,"20040401":0.24439,"20031001":0.59272,"19990901":0.38035,"19980201":0.15665,"20030301":0.21072,"19990701":0.24095,"19980701":NaN,"20091201":NaN,"20051001":0.46315,"20051101":0.92986,"20161101":NaN,"20110301":NaN,"20050601":0.18778,"20160801":NaN}; | |
var data5= | |
{"20010701":0.11882,"20020701":0.20701,"20050701":0.18126,"20021001":0.085665,"20141001":0.059534,"20100101":0.26486,"19990201":0.18264,"19991001":0.060979,"20080401":0.1118,"20070501":0.16741,"20160301":0.15311,"20100901":0.06635,"20060301":0.14655,"20030701":0.16234,"20150801":0.099845,"20120401":0.11087,"20150201":0.31453,"20160901":NaN,"20140101":0.36045,"20090101":0.26439,"20081001":0.069273,"20040801":0.093908,"20050201":0.25418,"20120601":NaN,"20120801":NaN,"20040901":0.071661,"20080801":0.088255,"20050301":0.13193,"20000301":0.12148,"20060901":0.066916,"20010401":0.1014,"20061001":0.10627,"20020201":0.23729,"20070101":0.3119,"20081101":0.17188,"20130701":NaN,"20100501":0.11535,"20110501":0.10029,"20000701":NaN,"20110901":0.09436,"20090401":0.11089,"20150601":1.1707,"20080201":0.30446,"20110601":NaN,"20151101":0.11435,"19990801":NaN,"20160101":0.27034,"19980401":0.094675,"20130901":NaN,"20140201":0.25719,"20091101":0.34233,"20020501":0.10458,"20040701":0.14318,"20121201":0.17697,"20021101":0.22959,"20010801":NaN,"19991101":0.13909,"20080701":0.112,"20070201":0.25674,"20090701":0.15208,"20131001":0.068506,"20040301":0.16346,"20090601":0.22692,"20160401":0.10215,"20110201":0.20891,"20160701":0.08867,"20071101":0.11191,"20030401":0.12049,"20060201":0.18848,"20150101":0.24955,"20141101":0.12028,"20070801":0.098262,"20140601":0.089733,"20051201":0.28194,"20101201":0.20644,"20100601":NaN,"20001001":0.076473,"19981201":0.15129,"20020801":0.061142,"20001101":0.11098,"20041001":0.17195,"19990401":0.096438,"20120101":0.35291,"20000201":0.14274,"20080101":0.32936,"20141201":0.35491,"20060801":0.081407,"19990101":0.1853,"20030601":0.21488,"20140901":NaN,"20111101":0.21297,"20130601":0.09437,"20150501":0.088575,"20000601":0.085075,"20080501":0.11306,"20061101":0.33491,"20020901":0.054647,"20050401":0.12076,"20031201":0.25839,"20100201":0.20882,"20030801":0.1264,"20030101":0.21925,"20011201":0.18885,"19980501":0.084739,"20130801":0.1096,"20070601":0.16254,"20140301":0.15705,"20070701":0.1407,"20001201":0.183,"20040601":0.20446,"20121101":0.29604,"20050801":0.077702,"19990601":0.098195,"20060501":0.1087,"19981101":0.14456,"20000101":0.17057,"20130301":0.13201,"20161201":0.14963,"19991201":0.22073,"20101101":0.20229,"20010901":0.060456,"20121001":0.16821,"20080601":0.12322,"20081201":0.31568,"20131101":0.18138,"20110101":0.25508,"20040201":0.20816,"20160501":0.092456,"20000901":0.055631,"20071001":0.094551,"20060101":0.27888,"20030501":0.12979,"19971001":0.16996,"20110701":NaN,"20010101":0.21034,"20150901":0.065483,"20031101":0.16819,"20140701":NaN,"20100701":0.1642,"20140401":0.1181,"20020601":0.1577,"19980801":0.08994,"20041101":0.27603,"20130501":0.094383,"20120201":0.27099,"20000501":0.11736,"20120901":0.068831,"20090201":0.22032,"20040501":0.13486,"20070901":0.066386,"20100401":0.10447,"20120501":0.10898,"20111001":0.07728,"20030201":0.17771,"19980601":0.094112,"20060701":0.1478,"20111201":0.23929,"20130101":0.23666,"20120701":NaN,"20061201":0.25836,"20150401":0.093974,"19980101":0.14769,"20010501":0.091834,"20020101":0.22216,"20110401":0.10189,"20050501":0.11488,"19970901":0.056357,"20100301":0.15253,"20011101":0.17808,"20030901":0.080273,"20090501":0.10811,"20011001":0.063824,"19971201":0.16637,"20151201":0.16088,"20070401":0.12179,"20131201":0.27333,"19990501":0.093484,"20040101":0.30553,"20070301":0.1447,"20160201":0.15236,"20041201":0.2222,"20020401":0.10084,"20100801":0.087161,"20110801":0.089364,"20060601":0.13887,"20091001":0.099368,"20150301":0.13546,"20130201":0.2775,"20071201":0.22097,"20050901":0.06445,"20101001":0.070022,"20140801":NaN,"19981001":0.052773,"20060401":0.11239,"20160601":0.099118,"19980301":0.13507,"20161001":0.083635,"20050101":0.23772,"20021201":0.217,"20080901":0.062129,"20000801":NaN,"20150701":0.18621,"20010201":0.20078,"19971101":0.13519,"20090801":0.09017,"20010301":0.13528,"20020301":0.1533,"20090901":0.05987,"20140501":0.098217,"19990301":0.12258,"20010601":0.1449,"19980901":0.067279,"20130401":0.089445,"20120301":0.151,"20000401":0.13409,"20080301":0.18749,"20090301":0.15618,"20151001":0.079181,"20040401":0.11901,"20031001":0.14483,"19990901":0.065646,"19980201":0.14441,"20030301":0.13561,"19990701":NaN,"19980701":NaN,"20091201":0.23818,"20051001":0.07545,"20051101":0.11398,"20161101":0.20583,"20110301":0.14047,"20050601":0.11976,"20160801":0.053956}; | |
var annualdata= {"2016":-0.77301,"1999":-0.74511,"1998":-0.72017,"2002":1.0223,"2003":0.55844,"2000":-0.73087,"2001":-0.76497,"2006":0.69162,"2007":0.20109,"2004":0.34528,"2005":0.78647,"2015":-0.76297,"2014":-0.74665,"2008":1.4257,"2009":0.73305,"2011":0.83247,"2010":-0.034487,"2013":-0.73345,"2012":-0.58473}; | |
var monthlydata={"February":1.0286,"October":1.5025,"March":0.96157,"August":4.3034,"May":1.044,"January":0.97282,"June":2.7125,"September":1.7589,"April":-5.51,"December":1.1369,"July":5.0953,"November":1.2853}; | |
function formatData(inputdata){ | |
var datajson=[]; | |
var keys = Object.keys(inputdata); | |
//console.log(keys); | |
keys.forEach(d => { | |
var date = d3.timeParse("%Y%m%d")(d); | |
var t = []; | |
t['date']= date; | |
t['Value']= +inputdata[d]; | |
datajson.push(t); | |
}); | |
return datajson; | |
} | |
function formatData_annual(inputdata){ | |
var datajson=[]; | |
var keys = Object.keys(inputdata); | |
//console.log(keys); | |
keys.forEach(d => { | |
var date = d3.timeParse("%Y")(d); | |
var t = []; | |
t['date']= date; | |
t['Value']= +inputdata[d]; | |
datajson.push(t); | |
}); | |
return datajson; | |
} | |
function formatData_month(inputdata){ | |
var datajson=[]; | |
var keys = Object.keys(inputdata); | |
// object which holds the order value of the month | |
var monthNames = { "January": 1, "February": 2, "March": 3, "April": 4, "May": 5, "June": 6, "July": 7, "August": 8, "September": 9, "October": 10, "November": 11, "December": 12}; | |
function sort(a, b) { | |
// Dates will be cast to numbers automatically: | |
return monthNames[a] - monthNames[b]; | |
} | |
keys = keys.sort(sort); | |
keys.forEach(d => { | |
var date = d3.timeParse("%B")(d); | |
var t = []; | |
t['date']= date; | |
t['Value']= +inputdata[d]; | |
datajson.push(t); | |
}); | |
return datajson; | |
} | |
//console.log(formatData_month(monthlydata)); | |
linegraph_m(formatData(data3),formatData(data5),'#div1','%b %Y'); | |
linegraph(formatData_annual(annualdata),'#div2','%Y'); | |
linegraph(formatData_month(monthlydata),'#div3','%B'); | |
function roundToGrid(input, array) { | |
var f= Math.floor(input); | |
var decimal = (input - Math.floor(input)).toFixed(2); | |
let closest = array.sort( (a, b) => Math.abs(decimal - a) - Math.abs(decimal - b) )[0]; | |
return (f+closest).toFixed(2); | |
} | |
//console.log((roundToGrid(29.33, [0.14,0.47,0.81]))); | |
//console.log((roundToGrid(39.8, [0.18,0.52,0.85]))); | |
</script> | |
</body> |