C3: How customize chart background with gradient color

Created on 28 Aug 2014  路  6Comments  路  Source: c3js/c3

C-feature-request question

All 6 comments

I struggled with this question too.
There are two probles:

  • injecting the gradient-markup into svg.defs
  • using it within the fill style

First one can be solved using some scripts like in the GoogleGroup thread but using it is a bit complicated cause c3 renders the element on various actions, so i think we should implement a simple api for that.

Got a working example here but like you see drawing the area background with the same color as the line color is an unpracticable solution.

http://jsfiddle.net/ha3L5z3b/

Hi @psi-4ward , I think this issue is about the background of chart, not area chart. However, It would be nice if we can set gradient color easily. So, I'll work on this later.

Combining methods from multiple sources, I arrived at this solution for changing the background of the chart -

//Set background opacity and fill
d3.selectAll('.chart g.c3-event-rects').style('fill-opacity', '1');
d3.selectAll('.chart g.c3-event-rects').style('fill', 'url(#something)');

//Insert gradient

let gradient = d3.select('defs')
.append('linearGradient')
.attr('id', 'gradient')
.attr('x1', '50%').attr('y1', '0%')
.attr('x2', '50%').attr('y2', '100%');

gradient
  .append('stop')
  .attr('offset', '0%')
  .attr('stop-color', '#FFFFFF')
  .attr('stop-opacity', '1');

gradient
  .append('stop')
  .attr('offset', '100%')
  .attr('stop-color', '#B38EE8')
  .attr('stop-opacity', '0');

It would be very nice if this was documented as well. I mean using gradients through inserting with d3 and using css notation as was mentioned in #1098 at least until support for gradients is made available

Hi,

The issue queue is to be used for reporting defects and problems with C3.js, in addition to feature requests and ideas.

It is not a catch-all support forum.

For general support enquiries, please use the Google Group at https://groups.google.com/forum/#!forum/c3js.

All questions involving the interplay between C3.js and any other library (such as AngularJS) should be posted there first!

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wojciechowskid picture wojciechowskid  路  3Comments

aishwaryak picture aishwaryak  路  4Comments

jstone-ponderosa picture jstone-ponderosa  路  3Comments

udhaya2kmrv picture udhaya2kmrv  路  3Comments

Zerim picture Zerim  路  3Comments