Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToolTip error on Bar Chart #426

Closed
alexanderwiebe opened this issue Jul 7, 2014 · 8 comments
Closed

ToolTip error on Bar Chart #426

alexanderwiebe opened this issue Jul 7, 2014 · 8 comments

Comments

@alexanderwiebe
Copy link

I have a bar chart that uses the following setup below:
example jsfiddle

In short, when there is a barchart that has multiple series where those series do not have the same length, the tooltip does not appear for those 'unmatched' columns. In the example below this would be for the columns at February - July.

Looking at the labels below, a tooltip should be displayed for each of the months below. However, because of the error at Chart.js line 1969 throws an error "Uncaught TypeError: Cannot read property 'highlightFill' of undefined "

I was curious if I would be able to fix this?

However I'm not sure if it would be better to build the undefined tolerance into the helpers foreach function or fix within the anonymous function to solve this issue.

var myBarChart = new Chart(ctx).Bar(data, options);
var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.5)",
            strokeColor: "rgba(220,220,220,0.8)",
            highlightFill: "rgba(220,220,220,0.75)",
            highlightStroke: "rgba(220,220,220,1)",
            data: [65]
        },
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.5)",
            strokeColor: "rgba(151,187,205,0.8)",
            highlightFill: "rgba(151,187,205,0.75)",
            highlightStroke: "rgba(151,187,205,1)",
            data: [28, 48, 40, 19, 86, 27, 90]
        }
    ]
};
@luisrudge
Copy link

I think you must provide all values, including 0's.
Working jsfiddle: http://jsfiddle.net/sGTA9/2/

@alexanderwiebe
Copy link
Author

The issue I see with that is two fold.

First, the bars are still visible in your example (although valued at 0).
Second, for something that doesn't have a value, 0 would not make sense.

For example if a chart used 2 series, one to represent my weight, the other to represent my target weight. I don't weight 0lbs next month, although I would have a value for my target. It wouldn't make sense to have values for something that hasn't happened yet or doesn't exist.

Further, there's a variety of instances, like in a chemical plant, where you might have a chart with multiple series each representing a value over time. If the sampling rate is not the same for each series having a value of 0 would be incorrect.

For example, say I have the temperature of boilers A, B, and C with respect to time. If A has a sample rate of every 1 min, B every 5 min, and C every 15 min and the temperatures are between 85 - 100C it would be misleading to have a value of 0 for B and C for each minute. I understand in this scenario it would be possible to use interpolation or break out the series to multiple graphs. However, I feel that the lack of a value should be an acceptable value, and it should not cause an error and not be visible on the chart or tooltip.

@luisrudge
Copy link

That's correct. I work with both null values and 0 values too and have the same problems :)
This has to be fixed indeed!

@nnnick nnnick added the bug label Jul 7, 2014
@nnnick
Copy link
Member

nnnick commented Jul 7, 2014

Thanks for reporting in such detail - that's certainly a bug.

Will try and get that sorted tomorrow evening and push a fix. From very quickly glancing at the issue, it looks like it just requires some defensive coding around whether a bar is actually there when getting the bars at that index from an event.

@nnnick
Copy link
Member

nnnick commented Jul 8, 2014

I've had a little bit more of a look into this and it's not quite as simple as I had originally thought - there were quite a few problems with using sparse datasets in Line, Bar and Radar charts.

I've set up a PR for some changes that fix your issues here if you want to take a look : #435

It's mostly done, just need to resolve an issue with the bezier curve spline points for line charts before it can get merged into master.

@nnnick
Copy link
Member

nnnick commented Aug 17, 2014

Sorry this took so long to resolve - just gone into master and tagged in the latest release now.

Now you can have sparse datasets and skip over some points by passing in a falsy value instead of a number.

@nnnick nnnick closed this as completed Aug 17, 2014
@philipwalton
Copy link

I'm still seeing this issue using 1.0.1-beta.4. Should it be fixed in that version?

Here's my stack track if that's helpful:

Uncaught TypeError: Cannot read property 'highlightFill' of undefined - Chart.js:2024
  (anonymous function) - Chart.js:2024
  helpers.each - Chart.js:178
  (anonymous function) - Chart.js:2023
  chartInstance.events.(anonymous function) - Chart.js:730

@acerov
Copy link

acerov commented Mar 15, 2016

Same here, is there a workaround except providing 0's?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants