FVANCOP / ChartNew.js

MIT License
420 stars 143 forks source link

Can i implement bar chart like bellow? #455

Closed EscApp2 closed 7 years ago

EscApp2 commented 7 years ago

Can i implement bar chart like in picture. http://picplus.ru/img/1608/09/c7817863.png I need to fill in the blank value other background. Is there a way? Can I add a different background for various bars.

Option "complementaryBar" works are not eligible for such bar chart http://picplus.ru/img/1608/09/41e5b6d7.png

Maybe I need to use addon "shapesInChart"? But is there any callback, which will fire after drawing each bar and return its coordinates, and not the coordinates of entire region?

Or is there in your opinion other way?

FVANCOP commented 7 years ago

Can you try following code :

 function setComplementaryColor(area,ctx,data,statData,posi,posj,othervars) {
     if(1*data.datasets[posi].data[posj]==0)return("rgba(220,220,0,0.3)");
     else return("rgba(0,0,0,0)");
 };

and set following options :

   complementaryBar : true,
    complementaryColor : setComplementaryColor,
    complementaryStrokeColor : "rgba(0,0,0,0)",

It produce following chart :

canvas

EscApp2 commented 7 years ago

Thanks for the help. But this is not exactly what I need.

I guess I'm not quite correctly expressed in the first post.

The problem for me is not changing color for zero or null value. (then using complementaryBar options ) The problem - that the complementaryBar should be extended above and below the X-axis. then we have such bar chart http://picplus.ru/img/1608/10/d3eeddb7.png

I want from this http://picplus.ru/img/1608/10/d3eeddb7.png make this http://picplus.ru/img/1608/10/b2235156.png where blue - is complementaryBar (or any other add-on that allows me to draw in such a way) grey - standart bar with positive value red - standart bar with negative value

FVANCOP commented 7 years ago

With current version, it is not possible. But, in the coming days, I will publish a new version; I will integrate this new feature in it.

EscApp2 commented 7 years ago

Thank you for your time. Using the addition "shapesInChart" and "Samples / issue_440.html" as example I achieved the required goals.

Thank you.

FVANCOP commented 7 years ago

Option complementaryBarFullHeight has been added to the last version. If you set it to true, the complementary bar is displayed on the full chart Height.

See https://github.com/FVANCOP/ChartNew.js/wiki/100_070_Charts_Layout#complementarybarfullheight