Write text into a bar element?
See original GitHub issueI’m trying to customize a stacked bar chart, and having some trouble figuring out the right way to inject some text into each bar. This is what I currently have, and it does inject a span
element, but its not actually getting visibly displayed. Not sure if its just that I’m not setting the height and width of the span or what. Anyone have any idea what I’m missing?
var chart = Chartist.Bar(this.getDOMNode(), chartData, chartOptions).on("draw", function (data) {
if (data.type === "bar") {
var label = new Chartist.Svg("span");
label.addClass("ct-label ct-horizontal");
label.text("Test");
data.element.append(label);
data.element.attr({
style: "stroke-width: 35px"
});
}
});
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Write text into a bar element? (Chart.js) - Ionic Forum
Hi, i made a stacked bar chart and i want to write some info in every stack.How can i write? import { Component...
Read more >Add a text box to a chart - Microsoft Support
Click the chart to which you want to add a text box. In Office 2013 and newer versions: On the Format tab, in...
Read more >How to write text above the bars on a bar plot (Python)?
plt.bar() returns a list of rectangles that can be used to position suitable text above each of the bars as follows:
Read more >Adding text to top of bar chart by appending text element
Hi all, I played around and change this original notebook, to this: Using join because I wanted to try to add some transitions...
Read more >Adding texts to bars - MuseScore
I've found it easiest to use a generic text line attached to the bar. Then you can use the start/end text from it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, I came up with a solution for this…and it was to use the
text
element as you suggested. For anyone who might need to do something similar in the future, here’s what I came up with:Handle the
draw
event of the chart with a function that looks something like this:And the result ends up looking something like this:
I’m open to suggestion if anyone has any ideas for how the above could be done better. Personally, key’ing off the class names of the parent feels a bit hackish, but it was the only thing I could find that uniquely identified each of the stacked bars. If there is something that would be better, please let me know.
This is fantastic, it would be great if you were able to add this to Chartist main code! Great job!