Highcharts Demo

author(s): Torstein Hønsi

by hendrikdegraaf

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>

CSS

#container {
    width: 900px;
    height: 600px;
    margin: 0 auto;
}

JavaScript

const renderer = new Highcharts.Renderer(
  document.getElementById('container'),
  600,
  300
);

const rect = renderer.rect(0, 50, 400, 100, 5).attr({
  fill: '#2caffe',
}).add();

const text = renderer.label('First text', 0, 10).attr({
  padding: 0,
  height: 150,
  fill: 'yellow'
}).css({
  fontSize: '150px',
 // lineHeight: '150px',
  color: 'red',
}).add();

const rect2 = renderer.rect(450, 50, 400, 100, 5).attr({
  fill: '#2caffe',
}).add();

const rectAsText = renderer.rect(450, 10, 60, 20).attr({
  fill: 'red'
}).add();

// Run animation on click
renderer.button('Align', 10, 250)
  .on('click', () => {
    // Align first one
    text.align({
        align: 'right',
        verticalAlign: 'top',
        alignByTranslate: false,
        x: text.getBBox().width * -1,
      },
      false,
      rect.getBBox()
    )

    // Align second one
    rectAsText.align({
        align: 'right',
        verticalAlign: 'top',
        alignByTranslate: false,
        x: rectAsText.getBBox().width * -1,
      },
      false,
      rect2.getBBox()
    )

  })
  .add();