# Heat Map months not aligning with map \[SOLVED\]

**URL:** <https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540>\
**Category:** General\
**Created:** [January 18, 2019, 11:54pm UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540 "2019-01-18T23:54:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozubergz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ozubergz/32/158960_2.png) [@ozubergz](https://forum.freecodecamp.org/u/ozubergz)\
**Post date:** [January 18, 2019, 11:54pm UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/1 "2019-01-18T23:54:42Z")

</div>

My y-axis display are labeled correctly, however they’re not lining up with the map data. I’m not sure how to fix it. Can someone shed some light on the problem or give some me advice?

Link to project: [https://codepen.io/Ozubergs/pen/bOzQVx?editors=0010](https://codepen.io/Ozubergs/pen/bOzQVx?editors=0010)

---

<div class="post-metadata">

**Author:** ![lasjorg](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lasjorg/32/280761_2.png) [@lasjorg](https://forum.freecodecamp.org/u/lasjorg)\
**Post date:** [January 19, 2019, 3:47am UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/2 "2019-01-19T03:47:31Z")

</div>

Don’t really know much about D3 but it looks to me like it is caused by the plus 1 in setUTCMonth.

`date.setUTCMonth(month + 1);`

You say your Y labels are correct but looking at [the example project](https://codepen.io/freeCodeCamp/pen/JEXgeY), it has January at the top and December on the bottom.

---

<div class="post-metadata">

**Author:** ![zNematoadz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/znematoadz/32/105185_2.png) [@zNematoadz](https://forum.freecodecamp.org/u/zNematoadz)\
**Post date:** [January 19, 2019, 9:04pm UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/3 "2019-01-19T21:04:52Z")

</div>

Substract one from `.attr('y', (d, i) => y(d.month))` and `.attr('data-month', (d) => d.month)`

```auto
 var cell = svg.append('g')
    .attr('transform', 'translate(' + (margin.left + 1) + ', ' + (margin.top + 0.5) + ')')
    .selectAll('rect')
    .data(dataset)
    .enter().append('rect')
    .attr('x', (d, i) => x(d.year))
    .attr('y', (d, i) => y(d.month - 1)) <------ 
    .attr('width', (d, i) => x.bandwidth())
    .attr('height', (d, i) => y.bandwidth())
    .attr('class', 'cell')
    .attr('data-year', (d) => d.year)
    .attr('data-month', (d) => d.month - 1) <------
    .attr('data-temp', (d) => data.baseTemperature + d.variance)
    .style('fill', (d, i) => threshold(data.baseTemperature + d.variance))

```

---

<div class="post-metadata">

**Author:** ![ozubergz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ozubergz/32/158960_2.png) [@ozubergz](https://forum.freecodecamp.org/u/ozubergz)\
**Post date:** [January 21, 2019, 8:59am UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/4 "2019-01-21T08:59:07Z")

</div>

Thanks for the help. Your solution actually passes all the test. However, y-axis still does not correspond with the data-month. It’s weird…

---

<div class="post-metadata">

**Author:** ![zNematoadz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/znematoadz/32/105185_2.png) [@zNematoadz](https://forum.freecodecamp.org/u/zNematoadz)\
**Post date:** [January 21, 2019, 3:17pm UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/5 "2019-01-21T15:17:06Z")

</div>

> [@lasjorg](#):
>
> date.setUTCMonth(month + 1);

change this value to :

```auto
date.setUTCMonth(month + 2);

```

---

<div class="post-metadata">

**Author:** ![ozubergz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ozubergz/32/158960_2.png) [@ozubergz](https://forum.freecodecamp.org/u/ozubergz)\
**Post date:** [January 21, 2019, 8:33pm UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/6 "2019-01-21T20:33:28Z")

</div>

Now it does not pass test #9

---

<div class="post-metadata">

**Author:** ![zNematoadz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/znematoadz/32/105185_2.png) [@zNematoadz](https://forum.freecodecamp.org/u/zNematoadz)\
**Post date:** [January 21, 2019, 10:26pm UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/7 "2019-01-21T22:26:11Z")

</div>

Sorry about that, Guess I should have tested it! 😕. I forked it and the tests are passing now and looks like everything is correct.

all changes should be marked with `//----changed`

> **[D3 HeatMap](https://codepen.io/znematoadz/pen/rPNNgv?editors=0010)**
>
> ...

---

<div class="post-metadata">

**Author:** ![ozubergz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ozubergz/32/158960_2.png) [@ozubergz](https://forum.freecodecamp.org/u/ozubergz)\
**Post date:** [January 21, 2019, 11:17pm UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/8 "2019-01-21T23:17:10Z")

</div>

Wow, thanks a lot. You’re smart

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:06pm UTC](https://forum.freecodecamp.org/t/heat-map-months-not-aligning-with-map-solved/252540/9 "2021-01-17T20:06:16Z")

</div>

Closed on January 17, 2021, 8:06pm UTC


