using “dy” attribute in d3 to align labels with ticks
This baffles me. I am trying to use the "dy" attribute on my d3 chart to align the labels with the ticks on this horizontal bar chart.
The documentation says:
The dy attribute indicates a shift along the y-axis on the position of an element or its content.
Here is the javascript. It pulls the text from the "Question" part of an array.
ticks.append("text")
.attr("class", "ylabel")
.attr("dy", "0em")
.attr("x", -9)
.attr("fill", "#000")
.style("text-anchor", "end")
.style("font-size", "x-small")
.text(function(d) { return d['Question']; })
.call(wrap, 600);
Since it's easier to illustrate, when I use "0em", "1em" or "2em" on "dy" I get very different effects. "0em" is too high. "1em" squishes multiple lines together (because of the wrap function), and "2em" wraps the text UPWARDS instead of downwards.
So how do I shift the labels to align with the ticks on the chart?
update
by systematically removing lines of javascript in the header, I found that the word_wrap function is pushing this text up and down in weird ways, making it hard to align with the node.
function wrap(text, width) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(/s+/).reverse(),
word,
line = ,
lineNumber = 0,
lineHeight = -2.0, // ems
x = text.attr("x"), //<-- include the x!
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy - 2.5 + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", lineHeight - dy + 3 + "em").text(word);
}
}
});
}
function cwrap(text, width) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(/s+/).reverse(),
word,
line = ,
lineNumber = 0,
lineHeight = 1.1, // ems
x = text.attr("x"),
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
}
}
});
}
By using cwrap
instead of wrap
I was able to make this work. Both functions are imperfect, and only work with text of a limited size (either 3 lines or 2 lines max). But it solved my problem.
javascript d3.js
add a comment |
This baffles me. I am trying to use the "dy" attribute on my d3 chart to align the labels with the ticks on this horizontal bar chart.
The documentation says:
The dy attribute indicates a shift along the y-axis on the position of an element or its content.
Here is the javascript. It pulls the text from the "Question" part of an array.
ticks.append("text")
.attr("class", "ylabel")
.attr("dy", "0em")
.attr("x", -9)
.attr("fill", "#000")
.style("text-anchor", "end")
.style("font-size", "x-small")
.text(function(d) { return d['Question']; })
.call(wrap, 600);
Since it's easier to illustrate, when I use "0em", "1em" or "2em" on "dy" I get very different effects. "0em" is too high. "1em" squishes multiple lines together (because of the wrap function), and "2em" wraps the text UPWARDS instead of downwards.
So how do I shift the labels to align with the ticks on the chart?
update
by systematically removing lines of javascript in the header, I found that the word_wrap function is pushing this text up and down in weird ways, making it hard to align with the node.
function wrap(text, width) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(/s+/).reverse(),
word,
line = ,
lineNumber = 0,
lineHeight = -2.0, // ems
x = text.attr("x"), //<-- include the x!
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy - 2.5 + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", lineHeight - dy + 3 + "em").text(word);
}
}
});
}
function cwrap(text, width) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(/s+/).reverse(),
word,
line = ,
lineNumber = 0,
lineHeight = 1.1, // ems
x = text.attr("x"),
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
}
}
});
}
By using cwrap
instead of wrap
I was able to make this work. Both functions are imperfect, and only work with text of a limited size (either 3 lines or 2 lines max). But it solved my problem.
javascript d3.js
I think you might also need to set the y position, which would be the bottom of the text. dy is the offset
– Katie.Sun
Nov 20 at 17:43
put the text/tspan elements in ag
and position thisg
aligned with the bar. use the DevTools to edit the DOM and look which value works.
– rioV8
Nov 20 at 18:00
@Katie.Sun is the "y" position relative to the chart or to one tick on the "y-axis" of the chart? I found this example: stackoverflow.com/questions/35785450/…
– Marc Maxson
Nov 20 at 20:56
Fairly certain it's relative to the chart. That would be why in the example you showed me the 'y' attribute function starts the same way, or similarly, for both the rectangle and the text components
– Katie.Sun
Nov 20 at 21:03
add a comment |
This baffles me. I am trying to use the "dy" attribute on my d3 chart to align the labels with the ticks on this horizontal bar chart.
The documentation says:
The dy attribute indicates a shift along the y-axis on the position of an element or its content.
Here is the javascript. It pulls the text from the "Question" part of an array.
ticks.append("text")
.attr("class", "ylabel")
.attr("dy", "0em")
.attr("x", -9)
.attr("fill", "#000")
.style("text-anchor", "end")
.style("font-size", "x-small")
.text(function(d) { return d['Question']; })
.call(wrap, 600);
Since it's easier to illustrate, when I use "0em", "1em" or "2em" on "dy" I get very different effects. "0em" is too high. "1em" squishes multiple lines together (because of the wrap function), and "2em" wraps the text UPWARDS instead of downwards.
So how do I shift the labels to align with the ticks on the chart?
update
by systematically removing lines of javascript in the header, I found that the word_wrap function is pushing this text up and down in weird ways, making it hard to align with the node.
function wrap(text, width) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(/s+/).reverse(),
word,
line = ,
lineNumber = 0,
lineHeight = -2.0, // ems
x = text.attr("x"), //<-- include the x!
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy - 2.5 + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", lineHeight - dy + 3 + "em").text(word);
}
}
});
}
function cwrap(text, width) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(/s+/).reverse(),
word,
line = ,
lineNumber = 0,
lineHeight = 1.1, // ems
x = text.attr("x"),
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
}
}
});
}
By using cwrap
instead of wrap
I was able to make this work. Both functions are imperfect, and only work with text of a limited size (either 3 lines or 2 lines max). But it solved my problem.
javascript d3.js
This baffles me. I am trying to use the "dy" attribute on my d3 chart to align the labels with the ticks on this horizontal bar chart.
The documentation says:
The dy attribute indicates a shift along the y-axis on the position of an element or its content.
Here is the javascript. It pulls the text from the "Question" part of an array.
ticks.append("text")
.attr("class", "ylabel")
.attr("dy", "0em")
.attr("x", -9)
.attr("fill", "#000")
.style("text-anchor", "end")
.style("font-size", "x-small")
.text(function(d) { return d['Question']; })
.call(wrap, 600);
Since it's easier to illustrate, when I use "0em", "1em" or "2em" on "dy" I get very different effects. "0em" is too high. "1em" squishes multiple lines together (because of the wrap function), and "2em" wraps the text UPWARDS instead of downwards.
So how do I shift the labels to align with the ticks on the chart?
update
by systematically removing lines of javascript in the header, I found that the word_wrap function is pushing this text up and down in weird ways, making it hard to align with the node.
function wrap(text, width) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(/s+/).reverse(),
word,
line = ,
lineNumber = 0,
lineHeight = -2.0, // ems
x = text.attr("x"), //<-- include the x!
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy - 2.5 + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", lineHeight - dy + 3 + "em").text(word);
}
}
});
}
function cwrap(text, width) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(/s+/).reverse(),
word,
line = ,
lineNumber = 0,
lineHeight = 1.1, // ems
x = text.attr("x"),
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
}
}
});
}
By using cwrap
instead of wrap
I was able to make this work. Both functions are imperfect, and only work with text of a limited size (either 3 lines or 2 lines max). But it solved my problem.
javascript d3.js
javascript d3.js
edited Nov 20 at 21:21
asked Nov 20 at 17:11
Marc Maxson
82711426
82711426
I think you might also need to set the y position, which would be the bottom of the text. dy is the offset
– Katie.Sun
Nov 20 at 17:43
put the text/tspan elements in ag
and position thisg
aligned with the bar. use the DevTools to edit the DOM and look which value works.
– rioV8
Nov 20 at 18:00
@Katie.Sun is the "y" position relative to the chart or to one tick on the "y-axis" of the chart? I found this example: stackoverflow.com/questions/35785450/…
– Marc Maxson
Nov 20 at 20:56
Fairly certain it's relative to the chart. That would be why in the example you showed me the 'y' attribute function starts the same way, or similarly, for both the rectangle and the text components
– Katie.Sun
Nov 20 at 21:03
add a comment |
I think you might also need to set the y position, which would be the bottom of the text. dy is the offset
– Katie.Sun
Nov 20 at 17:43
put the text/tspan elements in ag
and position thisg
aligned with the bar. use the DevTools to edit the DOM and look which value works.
– rioV8
Nov 20 at 18:00
@Katie.Sun is the "y" position relative to the chart or to one tick on the "y-axis" of the chart? I found this example: stackoverflow.com/questions/35785450/…
– Marc Maxson
Nov 20 at 20:56
Fairly certain it's relative to the chart. That would be why in the example you showed me the 'y' attribute function starts the same way, or similarly, for both the rectangle and the text components
– Katie.Sun
Nov 20 at 21:03
I think you might also need to set the y position, which would be the bottom of the text. dy is the offset
– Katie.Sun
Nov 20 at 17:43
I think you might also need to set the y position, which would be the bottom of the text. dy is the offset
– Katie.Sun
Nov 20 at 17:43
put the text/tspan elements in a
g
and position this g
aligned with the bar. use the DevTools to edit the DOM and look which value works.– rioV8
Nov 20 at 18:00
put the text/tspan elements in a
g
and position this g
aligned with the bar. use the DevTools to edit the DOM and look which value works.– rioV8
Nov 20 at 18:00
@Katie.Sun is the "y" position relative to the chart or to one tick on the "y-axis" of the chart? I found this example: stackoverflow.com/questions/35785450/…
– Marc Maxson
Nov 20 at 20:56
@Katie.Sun is the "y" position relative to the chart or to one tick on the "y-axis" of the chart? I found this example: stackoverflow.com/questions/35785450/…
– Marc Maxson
Nov 20 at 20:56
Fairly certain it's relative to the chart. That would be why in the example you showed me the 'y' attribute function starts the same way, or similarly, for both the rectangle and the text components
– Katie.Sun
Nov 20 at 21:03
Fairly certain it's relative to the chart. That would be why in the example you showed me the 'y' attribute function starts the same way, or similarly, for both the rectangle and the text components
– Katie.Sun
Nov 20 at 21:03
add a comment |
2 Answers
2
active
oldest
votes
In my experience it has been dX that you need to dynamically set to make things appear relative to others in D3. Here is an example of how I get labels to appear next to nodes on a Force Directed Graph
label = label.enter().append("text")
.attr("class", "label")
.attr("dx", function (d) { return d.radius * 1.25; })
.attr("dy", ".35em")
.attr("opacity", function (d) { if (d.radius <= 7) { return 0; } return 1; })
.attr("font-weight", "normal")
.style("font-size", 10)
.text(function (d) { return d.id; })
.merge(label);
The dX value is what you want to base off of what is being drawn, though without seeing the code regarding how the rest of the graph is drawn I'm not sure what attribute of your other elements you should base it off of.
Great @a-zibuda - I will play around with this. The chart has a lot of elements (as you can see) so it's hard for me to see how the ticks are assigned, looking at the code. The way I read your example.attr("dy", ".35em")
is that you're moving the text a third of 1em below the mid-line. When I tested my code, that doesn't explain why the wrapping is affected in weird ways when I set a "dy" value.
– Marc Maxson
Nov 20 at 20:52
add a comment |
In my specific case, the wrap function was forcing text to be misaligned with ticks on my chart in weird ways (including wrapping text upwards if the "dy" offset was "2em"). I had to adjust the wrap function to fix the "dy" problem.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398123%2fusing-dy-attribute-in-d3-to-align-labels-with-ticks%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In my experience it has been dX that you need to dynamically set to make things appear relative to others in D3. Here is an example of how I get labels to appear next to nodes on a Force Directed Graph
label = label.enter().append("text")
.attr("class", "label")
.attr("dx", function (d) { return d.radius * 1.25; })
.attr("dy", ".35em")
.attr("opacity", function (d) { if (d.radius <= 7) { return 0; } return 1; })
.attr("font-weight", "normal")
.style("font-size", 10)
.text(function (d) { return d.id; })
.merge(label);
The dX value is what you want to base off of what is being drawn, though without seeing the code regarding how the rest of the graph is drawn I'm not sure what attribute of your other elements you should base it off of.
Great @a-zibuda - I will play around with this. The chart has a lot of elements (as you can see) so it's hard for me to see how the ticks are assigned, looking at the code. The way I read your example.attr("dy", ".35em")
is that you're moving the text a third of 1em below the mid-line. When I tested my code, that doesn't explain why the wrapping is affected in weird ways when I set a "dy" value.
– Marc Maxson
Nov 20 at 20:52
add a comment |
In my experience it has been dX that you need to dynamically set to make things appear relative to others in D3. Here is an example of how I get labels to appear next to nodes on a Force Directed Graph
label = label.enter().append("text")
.attr("class", "label")
.attr("dx", function (d) { return d.radius * 1.25; })
.attr("dy", ".35em")
.attr("opacity", function (d) { if (d.radius <= 7) { return 0; } return 1; })
.attr("font-weight", "normal")
.style("font-size", 10)
.text(function (d) { return d.id; })
.merge(label);
The dX value is what you want to base off of what is being drawn, though without seeing the code regarding how the rest of the graph is drawn I'm not sure what attribute of your other elements you should base it off of.
Great @a-zibuda - I will play around with this. The chart has a lot of elements (as you can see) so it's hard for me to see how the ticks are assigned, looking at the code. The way I read your example.attr("dy", ".35em")
is that you're moving the text a third of 1em below the mid-line. When I tested my code, that doesn't explain why the wrapping is affected in weird ways when I set a "dy" value.
– Marc Maxson
Nov 20 at 20:52
add a comment |
In my experience it has been dX that you need to dynamically set to make things appear relative to others in D3. Here is an example of how I get labels to appear next to nodes on a Force Directed Graph
label = label.enter().append("text")
.attr("class", "label")
.attr("dx", function (d) { return d.radius * 1.25; })
.attr("dy", ".35em")
.attr("opacity", function (d) { if (d.radius <= 7) { return 0; } return 1; })
.attr("font-weight", "normal")
.style("font-size", 10)
.text(function (d) { return d.id; })
.merge(label);
The dX value is what you want to base off of what is being drawn, though without seeing the code regarding how the rest of the graph is drawn I'm not sure what attribute of your other elements you should base it off of.
In my experience it has been dX that you need to dynamically set to make things appear relative to others in D3. Here is an example of how I get labels to appear next to nodes on a Force Directed Graph
label = label.enter().append("text")
.attr("class", "label")
.attr("dx", function (d) { return d.radius * 1.25; })
.attr("dy", ".35em")
.attr("opacity", function (d) { if (d.radius <= 7) { return 0; } return 1; })
.attr("font-weight", "normal")
.style("font-size", 10)
.text(function (d) { return d.id; })
.merge(label);
The dX value is what you want to base off of what is being drawn, though without seeing the code regarding how the rest of the graph is drawn I'm not sure what attribute of your other elements you should base it off of.
answered Nov 20 at 19:27
A Zibuda
388
388
Great @a-zibuda - I will play around with this. The chart has a lot of elements (as you can see) so it's hard for me to see how the ticks are assigned, looking at the code. The way I read your example.attr("dy", ".35em")
is that you're moving the text a third of 1em below the mid-line. When I tested my code, that doesn't explain why the wrapping is affected in weird ways when I set a "dy" value.
– Marc Maxson
Nov 20 at 20:52
add a comment |
Great @a-zibuda - I will play around with this. The chart has a lot of elements (as you can see) so it's hard for me to see how the ticks are assigned, looking at the code. The way I read your example.attr("dy", ".35em")
is that you're moving the text a third of 1em below the mid-line. When I tested my code, that doesn't explain why the wrapping is affected in weird ways when I set a "dy" value.
– Marc Maxson
Nov 20 at 20:52
Great @a-zibuda - I will play around with this. The chart has a lot of elements (as you can see) so it's hard for me to see how the ticks are assigned, looking at the code. The way I read your example
.attr("dy", ".35em")
is that you're moving the text a third of 1em below the mid-line. When I tested my code, that doesn't explain why the wrapping is affected in weird ways when I set a "dy" value.– Marc Maxson
Nov 20 at 20:52
Great @a-zibuda - I will play around with this. The chart has a lot of elements (as you can see) so it's hard for me to see how the ticks are assigned, looking at the code. The way I read your example
.attr("dy", ".35em")
is that you're moving the text a third of 1em below the mid-line. When I tested my code, that doesn't explain why the wrapping is affected in weird ways when I set a "dy" value.– Marc Maxson
Nov 20 at 20:52
add a comment |
In my specific case, the wrap function was forcing text to be misaligned with ticks on my chart in weird ways (including wrapping text upwards if the "dy" offset was "2em"). I had to adjust the wrap function to fix the "dy" problem.
add a comment |
In my specific case, the wrap function was forcing text to be misaligned with ticks on my chart in weird ways (including wrapping text upwards if the "dy" offset was "2em"). I had to adjust the wrap function to fix the "dy" problem.
add a comment |
In my specific case, the wrap function was forcing text to be misaligned with ticks on my chart in weird ways (including wrapping text upwards if the "dy" offset was "2em"). I had to adjust the wrap function to fix the "dy" problem.
In my specific case, the wrap function was forcing text to be misaligned with ticks on my chart in weird ways (including wrapping text upwards if the "dy" offset was "2em"). I had to adjust the wrap function to fix the "dy" problem.
answered Nov 20 at 21:23
Marc Maxson
82711426
82711426
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398123%2fusing-dy-attribute-in-d3-to-align-labels-with-ticks%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think you might also need to set the y position, which would be the bottom of the text. dy is the offset
– Katie.Sun
Nov 20 at 17:43
put the text/tspan elements in a
g
and position thisg
aligned with the bar. use the DevTools to edit the DOM and look which value works.– rioV8
Nov 20 at 18:00
@Katie.Sun is the "y" position relative to the chart or to one tick on the "y-axis" of the chart? I found this example: stackoverflow.com/questions/35785450/…
– Marc Maxson
Nov 20 at 20:56
Fairly certain it's relative to the chart. That would be why in the example you showed me the 'y' attribute function starts the same way, or similarly, for both the rectangle and the text components
– Katie.Sun
Nov 20 at 21:03