Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

font size is not working in my d3.js code

Tags:

d3.js

i am writing d3.js for generating many charts and graphs.. but when there is no data i am just appending svg a text and writting "no data to display" and assigning some attributes like x y dy etc.. similarly font-size but except font size every thing is working .

why? here is my code

var svg = d3.select(selector).append("svg")   .attr("width", width + margin.left + margin.right)   .attr("height", height + margin.top + margin.bottom)   .append("g")   .attr("transform", "translate(" + margin.left + "," + margin.top + ")");  if (!data.IssueTrendsDAO.issueTrendList) {   svg.append("text")     .attr("font-size","34px")     .attr("y", 79)     .attr("x", 40)     .attr("dy", ".47em")                             .style("text-anchor", "start")     .style("fill", "#004669")     .style("font-weight", "bold")     .text("No data to display"); } 
like image 618
Saurabh Sinha Avatar asked Mar 08 '13 07:03

Saurabh Sinha


People also ask

How do I change the font size in a HTML script?

In HTML, you can change the size of text with the <font> tag using the size attribute. The size attribute specifies how large a font will be displayed in either relative or absolute terms. Close the <font> tag with </font> to return to a normal text size.

What does D3 mean in JavaScript?

D3. js (data-driven documents) is an open source JavaScript library that allows users to apply prebuilt data visualizations to their data. The code creates interactive graphics and data visualizations in common Web standards like HTML, CSS and SVG.

What is SVG D3 JS?

Advertisements. SVG stands for Scalable Vector Graphics. SVG is an XML-based vector graphics format. It provides options to draw different shapes such as Lines, Rectangles, Circles, Ellipses, etc. Hence, designing visualizations with SVG gives you more power and flexibility.


1 Answers

I think you'll find it works if you assign font-size as a style rather than as an attribute.

.style("font-size", "34px") 

(better yet, assign an id or class attribute and set all your styles in CSS)

like image 164
hornbake Avatar answered Sep 20 '22 10:09

hornbake