Best way to achieve multiline text in titles (tspans)
See original GitHub issueI noticed from reading the code that title text is split into tspan elements, when an array of strings is provided. Nice! I also noticed legends have the same feature. I guess the docs should be updated for these:
https://apexcharts.com/docs/options/xaxis/ https://apexcharts.com/docs/options/title/ https://apexcharts.com/docs/options/legend/
Anyway, I was trying to achieve multiline text and wondered what would be the ideal way. Just fiddling in the browser dev tools I managed to get the tspans below each other and roughly centered with some quite awkward parameters:
<text id="SvgjsText1120" font-family="Helvetica, Arial, sans-serif" x="77.5" y="359" text-anchor="middle" dominate-baseline="central" font-size="1rem" fill="#373d3f" class="apexcharts-xaxis-title-text " style="font-family: Helvetica, Arial, sans-serif;">
<tspan id="SvgjsTspan1121" dx="-30">Bla blabla bla blablabla bla bla.</tspan>
<tspan id="SvgjsTspan1122" dy="24" dx="-240">Blu blublublu blu blublublub blu blubl.</tspan>
</text>
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
SVG Multiline Text with tspan - Jarrett Meyer
The easiest solution is to break the lines into independent tspan elements. We want to produce an output that looks like this. <svg...
Read more >Chapter 4. Multiline SVG Text - O'Reilly
This chapter discusses the basic attributes to position spans of text, showing how you can move the virtual typewriter to a new point...
Read more ><tspan> - SVG: Scalable Vector Graphics - MDN Web Docs
The SVG element defines a subtext within a element or another element. It allows for adjustment of the style and/or position of that...
Read more >How to create multi-line <h1> - DEV Community
The challenge. Alt Text. Forget about the gray paragraph and focus on the title. You can see that it spans over two lines...
Read more >Align lines of text to center in SVG - Stack Overflow
I can align the text in each individual <tspan> by adding text-anchor="middle" to it. But how to do relative centric alignment of those...
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
SVG.js
has built-in support for creating multiline texts withtspan
. I will see how feasible it is to convert current text into a multiline by using those thenewLine()
method ofsvg.js
. https://svgjs.com/docs/2.7/elements/#svg-textYeah, the work is under progress. Here’s a sneak peek.
It will be finished in a couple of days.