Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts highlight single point on line

I am using Highcharts to draw a line graph. When the page loads, the line graph is drawn. Please note, that i got an y-Value for every x-Value starting from 0 till 700 ( 0,1,2,3,...,700). This is how i create the graph:

                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
                                                  }
                                             }]

                                         });

In my HTML-Page I got two buttons to increase/decrease (+1/-1) a number in a textfield, starting at 200. The number represents a x-Coordinate in the graph. I would like to highlight the shown number of my textfield in the graph with another color and a bigger point when the graph is loaded the first time and also when the user changes the number using one of these buttons. How can I do this?

I tried

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

in the onclick method of the buttons but it doesnt work.

Thanks for your answers!

like image 272
android Avatar asked Mar 13 '12 09:03

android


1 Answers

Using a marker we can do this:

$(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/

like image 57
rsilva4 Avatar answered Oct 23 '22 20:10

rsilva4