Skip to content

Stacked bar starting at negative values #1167

Closed
@carlkenne

Description

@carlkenne

I've been trying to get a bar chart starting at below 0 by changing the series values to negative [-10, 20, 40]. But so far this has been giving me some really strange results. Is there a correct way of doing this?

I want something looking like this:

image

Activity

ManuLintz

ManuLintz commented on Apr 16, 2019

@ManuLintz

If I understand well, this issue is adressed in that conversation: #835
The short answer is that the case of negative numbers in stacked bar charts doesn't seem to be supported as for now.

However there is an open PR that seems to implement that feature: #1113

rarias8404

rarias8404 commented on Sep 12, 2019

@rarias8404

I developed a solution using jQuery, maybe I can serve you. Here is the code
// Lower limit of the y axis const limit = $('.ct-series-a > line').first().attr('y1'); // If exist a ct-series-b if ($('.ct-series-b').length > 0) { $('.ct-series-a > line').each(function (index, element) { // If negative if (element.getAttribute('ct:value').valueOf() < 0) { // If the lower limit of the element of series b is below the value 0 (visual) on the Y axis // Then the lower limit will be equal to the value 0 (visual) of Y axis if ($('.ct-series-b > line').eq(index).attr('y1') > limit) { $('.ct-series-b > line').eq(index).attr('y1', limit); } } }); }

rarias8404

rarias8404 commented on Sep 12, 2019

@rarias8404

Take a look
graph

added a commit that references this issue on Nov 2, 2022
65febba
added a commit that references this issue on Nov 3, 2022
4123192
added a commit that references this issue on Nov 3, 2022
ce13067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @carlkenne@rarias8404@ManuLintz@Arantiryo

      Issue actions

        Stacked bar starting at negative values · Issue #1167 · chartist-js/chartist