25

Can we show a message using highcharts.When the data is not available? we have to show a message Example : No Data Available. If we have data hide : No Data Available message . in highcharts dynamically

  Highcharts.chart('container', {
  chart: {
     type: 'bubble',
     plotBorderWidth: 0,
     zoomType: 'xy'
   },
});
Kondal
  • 2,870
  • 5
  • 26
  • 40
  • Well yes. Just don't create the highchart and insert text saying "No Data Available". Without any code, this is the most help you're likely to get. – George Feb 17 '17 at 11:23
  • See example...http://jsfiddle.net/gh/get/jquery/2/highcharts/highcharts/tree/master/samples/highcharts/no-data-to-display/no-data-pie/ – Nitin Dhomse Feb 17 '17 at 11:24
  • can we increase font size and we need to must add no-data-to-display-js file – Kondal Feb 17 '17 at 11:29
  • @Kondal Can I know what extra details you require from existing answer. – Deep 3015 Aug 16 '17 at 05:34
  • if we have data still showing no data available message so,can we hide in highcharts if we have data – Kondal Aug 16 '17 at 05:37
  • 1
    check this [noData](http://api.highcharts.com/highcharts/noData) from docs.This example works fine and tested. Add example where you fail – Deep 3015 Aug 16 '17 at 06:19

8 Answers8

21

Include no-data-to-display.js file in your page. It comes bundled with highcharts. You can get it here otherwise: https://code.highcharts.com/modules/no-data-to-display.js

Default message is "No data to display". If you would like to modify it, you can do this:

Highcharts.setOptions({
    lang: {
        noData: 'Personalized no data message'
    }
});
Talha Khan
  • 219
  • 1
  • 4
15

You can use Highcharts Chart Renderer

Here's an example in JSFiddle

var chart = new Highcharts.Chart({

    chart: {
        renderTo: 'container'
    },

    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: []

}, function(chart) { // on complete

    chart.renderer.text('No Data Available', 140, 120)
        .css({
            color: '#4572A7',
            fontSize: '16px'
        })
        .add();

});
fustaki
  • 1,574
  • 1
  • 13
  • 20
14

Some of these other answers seem kind of crazy... here's a super basic solution I wanted to share:

Highcharts.setOptions({lang: {noData: "Your custom message"}})
var chart = Highcharts.chart('container', {
    series: [{
        data: []
    }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/no-data-to-display.js"></script>

<div id="container" style="height: 250px"></div>

Hope this helps someone

Cumulo Nimbus
  • 8,785
  • 9
  • 47
  • 68
  • 2
    apart from live example how your post differs from https://stackoverflow.com/a/42297065/8632727. It looks crazy – Patata Feb 05 '18 at 06:04
8

Based on your comment (if we have data still showing no data available message so,can we hide in highcharts if we have data).I think you are using fustaki's solution and don't want to use no-data-to-display.js module. Yes there is problem as mentioned .You can still use the same code by modifying it i.e add condition inside continuing function to check if series is empty or not, based on this render message.

var chart = new Highcharts.Chart({

chart: {
    renderTo: 'container'
  },

  xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  },

  series: []

}, function(chart) { // on complete
  if (chart.series.length < 1) { // check series is empty
    chart.renderer.text('No Data Available', 140, 120)
      .css({
        color: '#4572A7',
        fontSize: '16px'
      })
      .add();
  }
});

Fiddle demo

Deep 3015
  • 9,929
  • 5
  • 30
  • 54
5

For me with latest version it works like this:

const Highcharts = require('highcharts');

import NoDataToDisplay from 'highcharts/modules/no-data-to-display';
NoDataToDisplay(Highcharts);

Highcharts.setOptions({
  lang: {
    noData: 'No data is available in the chart'
  }
});
Patrik Laszlo
  • 4,906
  • 8
  • 24
  • 36
2

With the current version (v7.1.2) and connected no-data-to-display module (v7.1.2) you can show your 'no data' message when you create a chart object as Patrik said by setting lang.noData option.

To be able to change this message after the chart is created you need to call method

yourChartObject.showNoData('you new message')
Starina
  • 103
  • 2
  • 9
0
<script src="https://code.highcharts.com/modules/no-data-to-display.js"></script>

Highcharts.chart('container', {
    lang: {
        noData: "No data found"
    },
    noData: {
        style: {
            fontWeight: 'bold',
            fontSize: '15px'
        }
    },
    .
    .
});
Shivani
  • 153
  • 9
0

and then after series you should add:

 lang: {
    noData: 'Nessun dato presente'
 },
 noData: {
    style: {
         fontWeight: 'bold',
         fontSize: '15px',
         color: '#303030'
     }
},

and it will work just fine

Julia
  • 51
  • 1
  • 3