2

I am using the Chartist plugin for generating charts. I've noticed that it does different element generations through browsers.

In Internet Explorer, it uses the <text> element, but it is offset on the left by 70px. I want to move that element on the right 70px, but I can't achieve this. I've tried with the text-anchor, transform, some letter and word spacing hacks, but none of them work.

Here is the code I am trying to modify:

<text class="ct-label ct-horizontal ct-end" x="25" y="205" width="179" height="20">FEB-2015</text>

So, instead of X-20, I want X-90.

Here is a live demo

4
  • Just in IE? What version(s)?
    – BitBug
    Commented May 29, 2015 at 15:52
  • Yes, only in IE, at least 11.
    – Amar Syla
    Commented May 29, 2015 at 15:55
  • 2
    please include the necessary code to understand the issue in the question itslef. An MVCE would be great.
    – web-tiki
    Commented Jun 1, 2015 at 12:33
  • Also consider reporting the problem: github.com/gionkunz/chartist-js/issues .The labels are misaligned even in the examples on their website.
    – pawel
    Commented Jun 1, 2015 at 13:00

5 Answers 5

4
+100

Correct (but possibly slow) solution

This is a bug of the Chartist library. They are calculating their label position so it is not center-aligned to the category.

For the permanent solution, you need to take it up with them, so the bug is fixed on their side.

You can find author's contact details on this GitHub page.

Temporary solution

In the interim, you can apply a dirty fix by shifting the whole labels block to the right.

As IE11 ignores transform properties applied via CSS, we will need to apply it directly to the SVG node properties.

Since you have jQuery on your page, we'll use that for the simplicity sake:

<!--[if IE]>
<script>
$chart.on( 'created', function() {
  $( '.ct-labels' ).attr( 'transform', 'translate(70)' );
} );
</script>
<![endif]-->

Needless to say, this needs to go after your other chart code.

0

How about modifying x attribute via Javascript?

<![if !IE]>
<script>
document.getElementsByTagName("text")[0].setAttribute("x", 95);
</script>
<![endif]>
0

Text tag is child of svg g element. You can't change x/y position of g element but you can use transform="translate(x,y)":

<g transform="translate(70,0)" ... >
    <text class="ct-label ct-horizontal ct-end" x="25" y="205" width="179" height="20">FEB-2015</text>
    <text class="ct-label ct-horizontal ct-end" x="25" y="205" width="179" height="20">FEB-2015</text>
    ......
</g>

info on SVG G: http://tutorials.jenkov.com/svg/g-element.html

0

Add this to your style sheet:

text{
  position: relative;
  right: 0px;
  left: 50px;
}

It will remove your left transform and will move your <text></text> to right ( 50px )

2
  • Please elaborate your answer and explain how the code solves the problem.
    – David
    Commented Jun 4, 2015 at 15:56
  • I doubt that you can apply this CSS for HTML positioning to SVG elements.
    – Mehdi
    Commented Jun 7, 2015 at 20:47
0
 <!--[if IE]>
<script>
$chart.on( 'created', function() {
  $( '.ct-labels' ).attr( 'transform', 'translate(70)' );
} );
</script>
<![endif]-->
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.