--- id: 587d7faa367417b2b2512bd2 title: Add Labels to D3 Elements required: - src: 'https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js' challengeType: 6 videoUrl: '' localeTitle: أضف تسميات لعناصر D3 --- ## Description
يتيح لك D3 تصنيف عنصر رسم بياني ، مثل شريط ، باستخدام عنصر text SVG. مثل عنصر rect ، يحتاج عنصر text إلى سمات x و y ، لوضعه على لوحة SVG. يحتاج أيضًا إلى الوصول إلى البيانات لعرض هذه القيم. تمنحك D3 مستوى عالٍ من التحكم في كيفية تصنيفك للأشرطة.
## Instructions
الشفرة الموجودة في المحرر تقوم بالفعل بربط البيانات بكل عنصر text جديد. أولاً ، إلحاق عقد text إلى svg . بعد ذلك ، أضف سمات للإحداثيات x و y . يجب أن تُحسب بنفس الطريقة التي يتم بها حساب rect ، باستثناء أن قيمة y text يجب أن تجعل الملصق يجلس 3 وحدات أعلى من الشريط. وأخيرًا ، استخدم طريقة D3 text() لتعيين التسمية مساوية لقيمة نقطة البيانات. ملحوظة
لتسمية التسمية أعلى من الشريط ، حدد ما إذا كان يجب أن تكون قيمة y text 3 أكبر أو 3 أقل من قيمة y للشريط.
## Tests
```yml tests: - text: '' testString: 'assert($("text").eq(0).text() == "12" && $("text").eq(0).attr("y") == "61", "The first text element should have a label of 12 and a y value of 61.");' - text: يجب أن يحتوي عنصر text الثاني على تصنيف 31 وقيمة y 4. testString: 'assert($("text").eq(1).text() == "31" && $("text").eq(1).attr("y") == "4", "The second text element should have a label of 31 and a y value of 4.");' - text: يجب أن يكون لعنصر text الثالث علامة من 22 وقيمة y 31. testString: 'assert($("text").eq(2).text() == "22" && $("text").eq(2).attr("y") == "31", "The third text element should have a label of 22 and a y value of 31.");' - text: '' testString: 'assert($("text").eq(3).text() == "17" && $("text").eq(3).attr("y") == "46", "The fourth text element should have a label of 17 and a y value of 46.");' - text: '' testString: 'assert($("text").eq(4).text() == "25" && $("text").eq(4).attr("y") == "22", "The fifth text element should have a label of 25 and a y value of 22.");' - text: '' testString: 'assert($("text").eq(5).text() == "18" && $("text").eq(5).attr("y") == "43", "The sixth text element should have a label of 18 and a y value of 43.");' - text: '' testString: 'assert($("text").eq(6).text() == "29" && $("text").eq(6).attr("y") == "10", "The seventh text element should have a label of 29 and a y value of 10.");' - text: '' testString: 'assert($("text").eq(7).text() == "14" && $("text").eq(7).attr("y") == "55", "The eighth text element should have a label of 14 and a y value of 55.");' - text: '' testString: 'assert($("text").eq(8).text() == "9" && $("text").eq(8).attr("y") == "70", "The ninth text element should have a label of 9 and a y value of 70.");' ```
## Challenge Seed
```html ```
## Solution
```js // solution required ```