Highcharts stacked bar chart - how to get the stacks values












0















I have created an highcharts stacked bar chart, but when the data is skewed, the bars are not visible or the numbers overlap, as shown in below image.



enter image description here



I have seen many posts, but there is no out of the box solution for this, so i am making my custom solution.



I am setting a default height of 150 if the y value is less than 150.



enter image description here



This solution works, but the total of the bars now is shown to be 300 instead of the actual original value. How can i change the total stacklabel value on my own? I am unable to find a way to do that.



Here is the code to change the height to default values. I am storing the actual value in realValue variable in the point object.



chartOptions = {
type: CHARTING.CHART_OPTIONS.TYPE.COLUMN,
// On chart load, apply custom logic
events : {
load: function () {
var chart = this,
minColHeightVal = 150;

chart.series.forEach(function (s) {
s.points.forEach(function (p) {

if (p.y < minColHeightVal) {
p.update({
y: minColHeightVal,
realValue: p.y
}, false);
}
});
});

// How to iterate over the bars here and sum the actual value? i.e. point.realValue and set the stacklabel?


chart.redraw();
}
}
}









share|improve this question























  • Please post a Minimal, Complete, and Verifiable example.

    – ewolden
    Nov 16 '18 at 12:18
















0















I have created an highcharts stacked bar chart, but when the data is skewed, the bars are not visible or the numbers overlap, as shown in below image.



enter image description here



I have seen many posts, but there is no out of the box solution for this, so i am making my custom solution.



I am setting a default height of 150 if the y value is less than 150.



enter image description here



This solution works, but the total of the bars now is shown to be 300 instead of the actual original value. How can i change the total stacklabel value on my own? I am unable to find a way to do that.



Here is the code to change the height to default values. I am storing the actual value in realValue variable in the point object.



chartOptions = {
type: CHARTING.CHART_OPTIONS.TYPE.COLUMN,
// On chart load, apply custom logic
events : {
load: function () {
var chart = this,
minColHeightVal = 150;

chart.series.forEach(function (s) {
s.points.forEach(function (p) {

if (p.y < minColHeightVal) {
p.update({
y: minColHeightVal,
realValue: p.y
}, false);
}
});
});

// How to iterate over the bars here and sum the actual value? i.e. point.realValue and set the stacklabel?


chart.redraw();
}
}
}









share|improve this question























  • Please post a Minimal, Complete, and Verifiable example.

    – ewolden
    Nov 16 '18 at 12:18














0












0








0








I have created an highcharts stacked bar chart, but when the data is skewed, the bars are not visible or the numbers overlap, as shown in below image.



enter image description here



I have seen many posts, but there is no out of the box solution for this, so i am making my custom solution.



I am setting a default height of 150 if the y value is less than 150.



enter image description here



This solution works, but the total of the bars now is shown to be 300 instead of the actual original value. How can i change the total stacklabel value on my own? I am unable to find a way to do that.



Here is the code to change the height to default values. I am storing the actual value in realValue variable in the point object.



chartOptions = {
type: CHARTING.CHART_OPTIONS.TYPE.COLUMN,
// On chart load, apply custom logic
events : {
load: function () {
var chart = this,
minColHeightVal = 150;

chart.series.forEach(function (s) {
s.points.forEach(function (p) {

if (p.y < minColHeightVal) {
p.update({
y: minColHeightVal,
realValue: p.y
}, false);
}
});
});

// How to iterate over the bars here and sum the actual value? i.e. point.realValue and set the stacklabel?


chart.redraw();
}
}
}









share|improve this question














I have created an highcharts stacked bar chart, but when the data is skewed, the bars are not visible or the numbers overlap, as shown in below image.



enter image description here



I have seen many posts, but there is no out of the box solution for this, so i am making my custom solution.



I am setting a default height of 150 if the y value is less than 150.



enter image description here



This solution works, but the total of the bars now is shown to be 300 instead of the actual original value. How can i change the total stacklabel value on my own? I am unable to find a way to do that.



Here is the code to change the height to default values. I am storing the actual value in realValue variable in the point object.



chartOptions = {
type: CHARTING.CHART_OPTIONS.TYPE.COLUMN,
// On chart load, apply custom logic
events : {
load: function () {
var chart = this,
minColHeightVal = 150;

chart.series.forEach(function (s) {
s.points.forEach(function (p) {

if (p.y < minColHeightVal) {
p.update({
y: minColHeightVal,
realValue: p.y
}, false);
}
});
});

// How to iterate over the bars here and sum the actual value? i.e. point.realValue and set the stacklabel?


chart.redraw();
}
}
}






javascript charts highcharts bar-chart






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 10:10









Aseem GoyalAseem Goyal

1,75622140




1,75622140













  • Please post a Minimal, Complete, and Verifiable example.

    – ewolden
    Nov 16 '18 at 12:18



















  • Please post a Minimal, Complete, and Verifiable example.

    – ewolden
    Nov 16 '18 at 12:18

















Please post a Minimal, Complete, and Verifiable example.

– ewolden
Nov 16 '18 at 12:18





Please post a Minimal, Complete, and Verifiable example.

– ewolden
Nov 16 '18 at 12:18












1 Answer
1






active

oldest

votes


















0














Did you try to use minPointLength option? It may be a simpler solution in your case: https://api.highcharts.com/highcharts/series.column.minPointLength



However, using your code to get the wanted result, use stackLabels.formatter function:



        formatter: function() {
var series = this.axis.series,
x = this.x,
sum = 0;

series.forEach(function(s) {
if (s.points && s.points[x]) {
sum += s.points[x].realValue ? s.points[x].realValue : s.points[x].y
}
});

return sum;
}


Live demo: https://jsfiddle.net/BlackLabel/uocdykbL/



API Reference: https://api.highcharts.com/highcharts/yAxis.stackLabels.formatter






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335603%2fhighcharts-stacked-bar-chart-how-to-get-the-stacks-values%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Did you try to use minPointLength option? It may be a simpler solution in your case: https://api.highcharts.com/highcharts/series.column.minPointLength



    However, using your code to get the wanted result, use stackLabels.formatter function:



            formatter: function() {
    var series = this.axis.series,
    x = this.x,
    sum = 0;

    series.forEach(function(s) {
    if (s.points && s.points[x]) {
    sum += s.points[x].realValue ? s.points[x].realValue : s.points[x].y
    }
    });

    return sum;
    }


    Live demo: https://jsfiddle.net/BlackLabel/uocdykbL/



    API Reference: https://api.highcharts.com/highcharts/yAxis.stackLabels.formatter






    share|improve this answer




























      0














      Did you try to use minPointLength option? It may be a simpler solution in your case: https://api.highcharts.com/highcharts/series.column.minPointLength



      However, using your code to get the wanted result, use stackLabels.formatter function:



              formatter: function() {
      var series = this.axis.series,
      x = this.x,
      sum = 0;

      series.forEach(function(s) {
      if (s.points && s.points[x]) {
      sum += s.points[x].realValue ? s.points[x].realValue : s.points[x].y
      }
      });

      return sum;
      }


      Live demo: https://jsfiddle.net/BlackLabel/uocdykbL/



      API Reference: https://api.highcharts.com/highcharts/yAxis.stackLabels.formatter






      share|improve this answer


























        0












        0








        0







        Did you try to use minPointLength option? It may be a simpler solution in your case: https://api.highcharts.com/highcharts/series.column.minPointLength



        However, using your code to get the wanted result, use stackLabels.formatter function:



                formatter: function() {
        var series = this.axis.series,
        x = this.x,
        sum = 0;

        series.forEach(function(s) {
        if (s.points && s.points[x]) {
        sum += s.points[x].realValue ? s.points[x].realValue : s.points[x].y
        }
        });

        return sum;
        }


        Live demo: https://jsfiddle.net/BlackLabel/uocdykbL/



        API Reference: https://api.highcharts.com/highcharts/yAxis.stackLabels.formatter






        share|improve this answer













        Did you try to use minPointLength option? It may be a simpler solution in your case: https://api.highcharts.com/highcharts/series.column.minPointLength



        However, using your code to get the wanted result, use stackLabels.formatter function:



                formatter: function() {
        var series = this.axis.series,
        x = this.x,
        sum = 0;

        series.forEach(function(s) {
        if (s.points && s.points[x]) {
        sum += s.points[x].realValue ? s.points[x].realValue : s.points[x].y
        }
        });

        return sum;
        }


        Live demo: https://jsfiddle.net/BlackLabel/uocdykbL/



        API Reference: https://api.highcharts.com/highcharts/yAxis.stackLabels.formatter







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 14:43









        ppotaczekppotaczek

        6,7591211




        6,7591211
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335603%2fhighcharts-stacked-bar-chart-how-to-get-the-stacks-values%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine