簡體   English   中英

高圖中箱圖中標記的條件着色

[英]Conditional coloring of marker in box plot in highcharts

以下是盒圖的javascript,可以在此小提琴中查看。

$(function () {
    $('#container').highcharts({

        chart: {
            type: 'boxplot'
        },

        title: {
            text: 'Highcharts Box Plot Example'
        },

        legend: {
            enabled: false
        },

        xAxis: {
            categories: ['1', '2', '3', '4', '5'],
            title: {
                text: 'Experiment No.'
            }
        },

        yAxis: {
            title: {
                text: 'Observations'
            },
            plotLines: [{
                value: 932,
                color: 'red',
                width: 1,
                label: {
                    text: 'Theoretical mean: 932',
                    align: 'center',
                    style: {
                        color: 'gray'
                    }
                }
            }]
        },

        series: [{
            name: 'Observations',
            data: [
                [760, 801, 848, 895, 965],
                [733, 853, 939, 980, 1080],
                [714, 762, 817, 870, 918],
                [724, 802, 806, 871, 950],
                [834, 836, 864, 882, 910]
            ],
            tooltip: {
                headerFormat: '<em>Experiment No {point.key}</em><br/>'
            }
        }, {
            name: 'Outlier',
            color: 'black',
            type: 'scatter',
            data: [ // x, y positions where 0 is the first category
                [0, 644],
                [4, 718],
                [4, 951],
                [4, 969]
            ],
            marker: {
                fillColor: 'red'
            },
            tooltip: {
                pointFormat: 'Observation: {point.y}'
            }
        }]
    });
});

我的意圖是根據圓點的位置更改其顏色。 例如:如果異常值大於700,我希望它是橙色。 通常,可以使用格式化程序選項來完成此操作,該選項可用於高圖表某些格式的標簽。 有辦法可以做到嗎?

您可以在Highcharts中使用數據之前檢查數據,如果滿足要求,可以為每個點添加顏色值。 示例: http//jsfiddle.net/nshkf75s/

相關代碼部分:

    series: [{
        name: 'Observations',
        data: [
            [760, 801, 848, 895, 965],
            [733, 853, 939, 980, 1080, 'orange'],
            [714, 762, 817, 870, 918],
            [724, 802, 806, 871, 950],
            [834, 836, 864, 882, 910]
        ],
        keys: ['low','q1','median','q3','high','color'],
        ...

您可以為此使用zones屬性。

        zones: [{
            value: 700,
            color: 'orange'
        }, {
            color: 'white'
        }]

演示: http//jsfiddle.net/m3x3Lwc9/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM