NVD3 - Showing empty chart instead of noData message
Asked Answered
E

3

7

Is there a way to show an empty chart instead of the "No Data Available" message when there is no data to show?

http://jsfiddle.net/sammla/pYWkD/2/

data2 = [ 
    { 
      "key" : "A key" , 
      "values" : []
    }

];

Thanks!

Edessa answered 3/7, 2013 at 21:14 Comment(0)
T
8

You can "hack" this by having an empty array that contains an empty array:

data2 = [ 
  { 
    "key" : "A key" , 
    "values" : [[]]
  }
];
Trouble answered 3/7, 2013 at 21:17 Comment(5)
Can we have custom message instead of no chart or "No Data available" message?Seventeen
You would need to modify the source for that I think.Trouble
Should I modify the scatter.js? But I did not find any No Data Available message thereSeventeen
This is probably in a different file. You may want to ask a new question about this.Trouble
Please see my question here - #23582792Seventeen
Q
5

The answer provided by Lars works well when you do not want to show the noData message on a chart when its empty.

Recently I had charts with content being loaded dynamically. I found a similar question to this Updating with no data does not clear old data from the chart.

If a chart is populated with data and then update is called after the data has been emptied, the noData text will overlay the existing data.

Consider if the current data should be cleared from the chart as it can be confusing to see both at the same time.

I was not able to find a clean solution to that, So here's what I did to overcome it :

Used Lars answer to empty the chart :

data2 = [{
    "key" : "A key",
    "values" : [[]]
}]; 

And then added the code below.

d3.select('#chart svg').append("text")
        .attr("x", "235")
        .attr("y", "35")
        .attr("dy", "-.7em")
        .attr("class", "nvd3 nv-noData")
        .style("text-anchor", "middle")
        .text("My Custom No Data Message");

Even I am after a proper solution for it, to show the noData text without it overlaying the existing data. But for now this works perfectly.

Hope it helps some one, trying to achieve the same thing.

Quinonoid answered 14/2, 2014 at 9:41 Comment(0)
C
5

you can call noData and pass a string during the chart creation:

(coffeescript)

self.chart = nv.models.lineChart()
               .margin  left: 100, right: 100
               .useInteractiveGuideline true
               .transitionDuration 150
               .showLegend true
               .showYAxis true
               .showXAxis true
               .noData 'no data, there is'
Crosier answered 14/5, 2014 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.