question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line graphs and radar graphs tooltips don't show the right color

See original GitHub issue

// Charts
var bar, line, data, ctx, goalCals, cheatDays, makeUpDay, options, data2;

goalCals = 1400;
cheatDays = 1800;
makeUpDay = 1000;

data = {
  labels: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  datasets: [
    {
      fillColor: 'rgba(213, 217, 239, .6)',
      data: [1950, 1300, 1800, 1200, 1700, 0, 0]
    }, {
      fillColor: 'rgba(19, 42, 157, .6)',
      data: [cheatDays, goalCals, goalCals, makeUpDay, goalCals, goalCals, cheatDays]
    }
  ]
};

data2 = [
  {
    value: 1950,
    color:"#8696e2",
    label: "Sun"
  },
  {
    value: 1300,
    color:"#86e2b2",
    label: "Mon"
  },
  {
    value: 1800,
    color:"#f6a292",
    label: "Tues"
  },
  {
    value: 1200,
    color:"#eaf28f",
    label: "Wed"
  },
  {
    value: 1700,
    color:"#e286e1",
    label: "Thurs"
  },
  {
    value: 1000,
    color:"#eb8ba2",
    label: "Fri"
  },
  {
    value: 1300,
    color:"#f6ea92",
    label: "Sat"
  }
];

options = {
  scaleOverride: true,
  scaleSteps: 2,
  scaleStepWidth: goalCals,
  scaleStartValue: 0,
  scaleBeginAtZero: true,
  scaleGridLineWidth: 0,
  barValueSpacing: 0,
  scaleLineColor: '#fff',
  barDatasetSpacing: 0,
  tooltipFillColor: 'rgba(0, 0, 0, .9)',
  tooltipTitleFontColor: '#fff',
  tooltipFontColor: '#fff',
  tooltipTitleFontStyle: 'normal',
  responsive: true,
  scaleShowGridLines: false,
  scaleFontColor: '#444',
  bezierCurveTension: .2,
  segmentStrokeWidth: 1
};


var chart = function(type, data) {
  var t = type.toLowerCase(),
      ctx = t + 'Ctx';
  ctx = $('.'+t+'-graph').get(0).getContext('2d');
  if(t === 'bar') {
    bar = new Chart(ctx).Bar(data, options);
  }
  if(t === 'line') {
    line = new Chart(ctx).Line(data, options);
  }
  if(t === 'radar') {
    radar = new Chart(ctx).Radar(data, options);
  }
  if(t === 'polararea') {
    polararea = new Chart(ctx).PolarArea(data, options);
  }
  if(t === 'pie') {
    pie = new Chart(ctx).Pie(data, options);
  }
  if(t === 'doughnut') {
    doughnut = new Chart(ctx).Doughnut(data, options);
  }
};

chart('Bar', data);
chart('Line', data);
chart('Radar', data);
chart('PolarArea', data2);
chart('Pie', data2);
chart('Doughnut', data2);

Thoughts? Bar graphs seem to be the only ones that show color. Polar charts and such don’t have a color block with them.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bisibukacommented, Sep 21, 2016

Here is a fork of above jsbin fork

http://jsbin.com/helivebeqo/edit?html,js,output

Hover any point and you can see that colors of the points inside the tooltip are black (don’t respect backgroundColor specified in datasets objects ). As you can see issue is still there. Any thoughts have this can be fixed?

1reaction
nnnickcommented, Jul 27, 2014

It actually uses the point colour for the legend. Not sure if that’s the best solution.

I wonder if a better way would be to use the line colour by default but allow an override or something. Open to suggestions there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Color the Tooltip Based on the Line Color in Chart.js
With chart js you can make line chart, bar chart, pie chart, doughnut chart, scatter chart, polar area chart, radar chart, gauge chart...
Read more >
Tooltip | Chart.js
Returns the colors for the text of the label for the tooltip item. labelPointStyle, TooltipItem, object | undefined, Yes, Returns the point ...
Read more >
Customizing the Tooltips
Macro name Description Supported by Format $seriesName Represents the series name All multi‑series charts chart... $yAxisName Represents the y‑axis name All Cartesian (x‑ and y‑coordinate)...
Read more >
Tooltip | Common Settings
By default, the tooltip is being shown when a point on a chart is hovered over. To disable them from showing at all,...
Read more >
Tooltips – amCharts 5 Documentation
In such case, tooltip will take series first bullet (if available) and use it as a source for its colors. TypeScript / ES6...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found