Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Highcharts.js charts look good on mobile and desktop

I'm wondering if anyone has successfully implemented a responsive design using Highcharts to make their charts look good on both mobile and desktop.

By default, Highcharts do re-scale when you resize the browser screen its just that the X-axis get cluttered by the tick mark text and bar graphs look tall and too skinny (too compressed). To get a sense of what I mean, you can go to this page and resize the browser.

I think these issues could possibly be addressed by reducing the amount of data points say to 1/3 of the original number though I'm wondering how that would be accomplished programmatically using Highcharts's API. If that doesn't sound like a good idea I'm also interested in other thoughts or solutions people might have come up with to use Highcharts on mobile (or perhaps even different JS charting libraries where a multi-device solution might be easier to implement?).

like image 452
tim peterson Avatar asked Jul 12 '12 10:07

tim peterson


People also ask

How do I get Started with Highcharts?

Getting started with Highcharts takes a bit of research if you are fairly new to programming in Javascript (like we were). Given the demo examples in JS Fiddle, however, you can always start with working code and go from there. Our chart is actually made up of two individual charts.

Why Highcharts for frameworks?

At Highcharts, we believe that good frameworks make developers’ lives easier. And we’ve found reasons to fall in love with virtually every framework out there! In support of fellow Angular, Vue and React developers across the world, we’ve developed official Highcharts wrappers for all these major frameworks, with more to come.

What is the use of container Div in Highcharts?

The container div is used to contain the chart drawn using the Highcharts library Highcharts library uses very simple configurations using json syntax. Here json represents the json data and configuration which HighChart library uses to draw a chart withing container div using highcharts () method.

Do Highcharts re-scale when you resize the browser screen?

By default, Highcharts do re-scale when you resize the browser screen its just that the X-axis get cluttered by the tick mark text and bar graphs look tall and too skinny (too compressed). To get a sense of what I mean, you can go to this pageand resize the browser.


3 Answers

The solution seems rather simple.

Just don't give the graph's a fixed width, i.e., don't define the width or set width:100% and, unlike the demo I mention, the bar chart width and accompanying bars will shrink as much as the browser width is reduced.

like image 132
tim peterson Avatar answered Sep 20 '22 12:09

tim peterson


It probably depends on which types of charts that you are displaying. On mobile, if you're displaying a column chart, you might want to rotate the chart so that it becomes a bar chart.

If you're displaying a line chart, you could "scope" the data, so that you're only displaying the least amount of points needed to get the point across. As you zoom in, re-scope the data to fit the current view. This can be done using some events combined with some hand rolled js.

like image 20
Matthew Crist Avatar answered Sep 19 '22 12:09

Matthew Crist


You can set the chart container div width:100% . Then just remove the highchart width property. I resolved it for a sparkline chart. Now it is mobile responsive.

Highcharts.chart('my-sparkline-chart, {
        chart: {
            type: 'areaspline',
            height: '70',
            //width: '189', //comment width property.
            spacing: [0, 0, 0, 0],
            backgroundColor: "transparent"
        }
...
like image 20
Asaprab Avatar answered Sep 21 '22 12:09

Asaprab