简体   繁体   English

如何使用jQuery选择路径标签

[英]How to select a path tag using jQuery

I have made a Box Plot chart (Highcharts) , Here's my example: 我已经制作了箱形图(Highcharts),这是我的示例:

https://jsfiddle.net/hew8nq5u/ https://jsfiddle.net/hew8nq5u/

My code is: 我的代码是:

 Highcharts.chart('container', {

        chart: {
            type: 'boxplot'
        },

        title: {
            text: 'All Patients'
        },

        legend: {
            enabled: true
        },

        xAxis: {
            categories: ['Asia Pacific', 'Europe', 'Latin America', 'North America', 'SWAC'],
            title: {
                text: '      '
            }
        },

        yAxis: {
            title: {
                text: 'Annual Center Volume 2016'
            },
            tickInterval: 5,
            min: 0,
            max: 75
            //plotLines: [{
            //    value: 932,
            //    color: 'red',
            //    width: 1,
            //    label: {
            //        text: 'Theoretical mean: 932',
            //        align: 'center',
            //        style: {
            //            color: 'gray'
            //        }
            //    }
            //}]
        },
        //colors: ['#91e8e1', '#7cb5ec', '#434348', '#90ed7d', '#f7a35c',
        //         '#8085e9', '#f15c80', '#e4d354', '#2b908f', '#f45b5b', ], //updates default colors
        plotOptions: {
            boxplot: {
                fillColor: '#F0F0E0',
                lineWidth: 2,
                upperQuartileColor: 'green',
                lowerQuartileColor: 'green',
                medianColor: '#0C5DA5',
                medianWidth: 3,
                stemColor: '#A63400',
                stemDashStyle: 'solid',
                stemWidth: 1,
                whiskerColor: '#3D9200',
                whiskerLength: '20%',
                whiskerWidth: 3                 
            }
        },
        series: [{
            name: 'Region Runs',
            showInLegend: false,
            //colorByPoint: true,
            color: 'red',
            data: [
                [2, 4, 18, 43, 53],
                [5, 9, 16.5, 32, 52],
                [1, 3, 6, 11.5, 21],
                [3, 9, 20, 38, 73],
                [1, 2, 8, 16, 20]
            ],
            tooltip: {
                headerFormat: '<em>Experiment No {point.key}</em><br/>'
            }
        },
        {
            name: '75th Percentile',
            type: 'line', 
            color: 'red',
            marker: {
                symbol: 'square'
            },

        },
        {
            name: 'Median',
            type: 'line',
            color:'#0C5DA5',
            marker: {
                symbol: 'square'
            },

        },
        {
            name: '25th Percentile',
            type: 'line', 
            color: 'red',
            marker: {
                symbol: 'square'
            },

        },
        {
            name: '90th percentile',
            type: 'line',
            color: '#3D9200',
            marker: {
                symbol: 'square'
            },

        },{
            name: '10th percentile',
            type: 'line',
            color: '#3D9200',
            marker: {
                symbol: 'square'
            },

        }//,
        //{
        //    name: 'IQR',
        //    type: 'line',
        //    color: 'brown',
        //    marker: {
        //        symbol: 'square'
        //    },

        //},
        //{
        //    name: 'Outlier',
        //    color: Highcharts.getOptions().colors[0],
        //    type: 'scatter',
        //    data: [ // x, y positions where 0 is the first category
        //        [0, 128],
        //        [1, 161],
        //        [2, 58],
        //        [3, 204],
        //        [4,42]
        //    ],
        //    marker: {
        //        fillColor: 'white',
        //        lineWidth: 1,
        //        lineColor: Highcharts.getOptions().colors[0]
        //    },

        //    tooltip: {
        //        pointFormat: 'Observation: {point.y}'
        //    }


        //}
        ]

    });

I would like to have top of the box and bottom of the box in different colors, and also top of the whisker and bottom of the whisker in different colosr for each box (region). 我想让每个盒子(区域)的盒子顶部和盒子底部具有不同的颜色,并且晶须的顶部和晶须的底部具有不同的颜色。 But all of the lines in the box are in the same color (red) and top and bottom of the whisker are in the same color (green). 但是框中的所有线条都使用相同的颜色(红色),晶须的顶部和底部使用相同的颜色(绿色)。

I've found currently it's not possible in highcharts to have box bottom and top in different colors. 我发现目前在highcharts中不可能用不同的颜色来显示底部和顶部。 Same with top and bottom whiskers. 与顶部和底部晶须相同。 Because of that, I want to resolve the issue, by selecting the element "path" (its class) using jQuery and appending html in it to change the color in yellow. 因此,我想通过使用jQuery选择元素“ path”(其类)并在其中添加html来将颜色更改为黄色来解决此问题。 Something like this: 像这样:

$(".highcharts-boxplot-whisker").append("<path fill='none' class='highcharts-boxplot-whisker' stroke='yellow' stroke-width='3' d='M 59.1 80.5 L 71.9 80.5'></path>");

But something is wrong with my selector, nothing happened. 但是我的选择器出了点问题,什么也没发生。 How can I do this? 我怎样才能做到这一点? Thank you in advance for any help. 预先感谢您的任何帮助。 The tag that I want to select 我要选择的标签

You can change borders using jQuery css() ! 您可以使用jQuery css()更改边框! :) :)

 div { height: 100px; width: 100px; margin: 40px auto; background-color: pink; } 
 <div></div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> <script> $("div").css("border-top", "5px solid blue"); $("div").css("border-bottom", "5px solid red"); </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM