Daniel Bogart
Daniel Bogart

Reputation: 1295

Highcharts area spline values have incorrect position on y-axis

I have an area spline highchart that seems to incorrectly place data points along the y-axis. I'm using the angular-highcharts directive and delivering the chart options through my service. The data itself is correct, as are the labels, the points are just placed too high along the y-axis. See image and code below:

simple area spline

Service function:

    function getReportingChart(quarterlyData, chartType, reportingType) {
        // extract top 4 drugs
        var top4 = _.sortBy(quarterlyData, 'x2q2').reverse().slice(0, 4);

        var dataSeries = [];
        var firstDrug = quarterlyData[0];
        var seriesNumber = 0;
        var quarters = ['Q1 2012', 'Q2 2012', 'Q3 2012', 'Q4 2012', 'Q1 2013', 'Q2 2013', 'Q3 2013', 'Q4 2013', 'Q1 2014', 'Q2 2014'];

        _.each(top4, function (drug) {
            var name = drug.A;
            var dataArray = [];

            dataArray.push(drug.x0q1);
            dataArray.push(drug.x0q2);
            dataArray.push(drug.x0q3);
            dataArray.push(drug.x0q4);
            dataArray.push(drug.x1q1);
            dataArray.push(drug.x1q2);
            dataArray.push(drug.x1q3);
            dataArray.push(drug.x1q4);
            dataArray.push(drug.x2q1);
            dataArray.push(drug.x2q2);

            var newDataSet = new buildSeries(name, dataArray, seriesNumber);
            dataSeries.push(newDataSet);
            console.log(newDataSet);

            seriesNumber += 1;
        });

        return {
            options: {
                chart: {
                    type: chartType
                },
                plotOptions: {
                    series: {
                        stacking: 'normal'
                    }
                },

            },
            series: dataSeries,
            title: {
                text: 'Top 4 Drugs By ' + annotateChartByType(reportingType).titleSuffix
            },
            credits: {
                enabled: false
            },
            loading: false,
            xAxis: {
                categories: quarters,
                tickmarkPlacement: 'between',
                labels: {},
                min: 0.5,
                max: quarters.length - 1.5,
                startOnTick: false,
                endOnTick: false
            },
            yAxis: {
                title: {
                    text: annotateChartByType(reportingType).yAxis.title
                },
                labels: {
                    format: annotateChartByType(reportingType).yAxis.unitformat
                }
            },
            size: {}
        };


    }

Below is the annotateChartByType function:

    function annotateChartByType(params){
        var defaultOption = {titleSuffix:" Primary Reports", yAxis: {title: "Number of Reports", unitformat: '{value}'}};

        switch (params) {
            case 'ps-cases':
                return defaultOption;
            case 'patients':
                return {titleSuffix:" Patient Incidence Rate",yAxis: {title: "Incidence Rate", unitformat: '{value:,.2f} %'}};
            case 'serious-outcomes':
                return {titleSuffix:" Outcome Rate", yAxis: {title: "Incidence Rate", unitformat: '{value:%.2f} %'}};
            case 'serious-adverse-events':
                return {titleSuffix:" Serious AE Rate", yAxis: {title: "Incidence Rate", unitformat: '{value:%.2f} %'}};
            default:
                return defaultOption;
        }
    }

Upvotes: 3

Views: 1028

Answers (1)

Halvor Holsten Strand
Halvor Holsten Strand

Reputation: 20536

This is because you have:

plotOptions: {
    series: {
        stacking: 'normal'
    }
}

This means that the value you are seeing is indeed correct for the blue series, but it is stacked upon three other series, which makes it go higher on the y-axis. If this is unintentional just remove this code.

If it is intentional you can get the total instead of the series value using the total value in a formatter or pointFormat. See this pointFormat example:

tooltip: {
    pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y}</b> ({point.total})<br/>'
}

See this JSFiddle demonstration. This is the default with the parenthesis added to show the total.

Upvotes: 5

Related Questions