Highcharts突出显示单点在线

时间:2012-03-13 09:57:18

标签: javascript graph charts highcharts

我使用Highcharts绘制折线图。 页面加载时,绘制折线图。请注意,我得到的每个x值的y值从0到700(0,1,2,3,...,700)。这就是我创建图表的方式:

                chart = new Highcharts.Chart({
                                    chart: {
                                         renderTo: 'container',
                                         animation: false,
                                         type: 'line',
                                         marginTop: null,
                                         marginRight: 55,
                                         marginBottom: 50,
                                         marginLeft: 80,
                                         backgroundColor: backgroundColor,
                                         spacingTop: 10,
                                         spacingRight: 10,
                                         spacingBottom: 15,
                                         spacingLeft: 10,
                                         },
                                   title: {
                                         text: ' Graph',
                                         style: {color: graphLabelColor},
                                         x: -20 //center
                                         },
                                   xAxis: {
                                         title: {
                                         text: 'xAXIS',
                                         style: {
                                            color: axisLabelColor
                                            },
                                         },
                                         min:0,
                                         max: 600,
                                         gridLineColor: gridLineColor,
                                         minorTickInterval: 50,
                                         minorTickLength: 1,
                                         tickInterval: 100,
                                         minorGridLineWidth: 0,
                                         gridLineWidth: 1,
                                         lineColor: axisColor,
                                         labels: { 
                                            style : {
                                                color: axisColor
                                                }
                                            },
                                         plotLines: [{
                                                     value: 0,
                                                     width: 0,
                                                     color: axisColor
                                                     }]
                                         },
                                  yAxis: {
                                         title: {
                                            text: 'yAxis',
                                            style: {color: 
                                                axisLabelColor
                                            },
                                         },
                                         min:0,   
                                         max: 700,
                                         gridLineColor: gridLineColor,
                                         lineColor: axisColor,
                                         minorTickInterval: 50,
                                         minorTickLength: 1,
                                         minorGridLineWidth: 0,
                                         tickInterval: 100,
                                         labels: { 
                                            style: { 
                                                color: axisColor
                                            }
                                         },
                                         plotLines: [{
                                                     value: 0,
                                                     width: 0,
                                                     color: axisColor
                                                     }]
                                         },
                                    exporting: {
                                         enabled: false
                                         },
                                    tooltip: {
                                            enabled: true,
                                            borderColor: crosshairColor,
                                            crosshairs: [{
                                                width: 1,
                                                color: crosshairColor,
                                            },
                                                {
                                                width: 1,
                                                color: crosshairColor,
                                            }],
                                            formatter: function() {
                                                return '<b>'+ this.series.name +'</b><br/>'+this.y +' & '+ this.x.toFixed(0);
                                                }
                                         },
                                     legend: {
                                            layout: 'vertical',
                                            align: 'right',
                                            verticalAlign: 'top',
                                            x: -10,
                                            y: 100,
                                            borderWidth: 1,
                                            borderColor: plotlineColor,
                                            enabled: false,
                                            floating: true,
                                            shadow: true
                                            },
                                     plotOptions: {
                                            series: {
                                                enableMouseTracking: true
                                            },
                                            line: {
                                                color:plotlineColor,
                                                },
                                            },
                                     series: [{
                                             lineWidth: 2,
                                             name: carname,
                                             data: dataArray,
                                             marker: {
                                                  color:crosshairColor,
                                                  radius: 1
                                                  }
                                             }]

                                         });

在我的HTML页面中,我有两个按钮来增加/减少(+ 1 / -1)文本字段中的数字,从200开始。数字表示图中的x坐标。 我想在第一次加载图表时以及当用户使用其中一个按钮更改数字时,使用另一种颜色和更大的点突出显示图表中文本字段的显示数量。我怎么能这样做?

我试过

       chart.series[0].options.data[valueOfTextfield].color = 'yellow';
       chart.redraw(true);

在按钮的onclick方法中,但它不起作用。

感谢您的回答!

2 个答案:

答案 0 :(得分:7)

使用marker我们可以这样做:

$(function () {
    $('#container').highcharts({
        chart: {
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },



        series: [{
            data: [29.9, { marker: {
                    fillColor: '#FF0000',
                    lineWidth: 3,
                    lineColor: "#FF0000" // inherit from series
            },y:71.5}, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
        }]
    });
});

http://jsfiddle.net/zR4Kn/

答案 1 :(得分:5)

使用点对象的select方法 http://api.highcharts.com/highcharts#series。point.events.select