rails-highchats- tooltip

之前在 rubychina 上自己提出的问题:

怎么能获取到highchart中选定点的index,如果,当鼠标移到红色位置时,获取index为4 (从左至右)

http://ruby-china.org/topics/14045

 

<script type="text/javascript" >

  var chart;
  var chart_compare_price_json = <%= raw @chart_json_datas.to_json %>
  var chart_attr_value_json = <%= raw @attr_value_json_datas.to_json %>

$(document).ready(function() {

        data_info = chart_compare_price_json;
        attr_value_data = chart_attr_value_json;
      

        chart = new Highcharts.Chart({   
            chart: {  
            	renderTo: 'container',
            	backgroundColor: "#eeeeee"
            },  
            title: {
            	text: "供应商报价",
            	align: "center"
            },
            yAxis: {
            	title: {
            		text: "报价"
            	}
            },
            xAxis: {   
            	categories: [<%= @charts_x_data.map{|x|"'#{x}'"}.join(",") %>] ,
                plotLines: [{ // mark the weekend    
                    color: 'red',    
                    width: 2,    
                    value: 0,   //最低报价,value的值为竖线的位置,与index类似
                    dashStyle: 'ShortDash'    
                },{ // mark the weekend    
                    color: 'red',    
                    width: 2,    
                    value: <%= @average_price_index %>,  //平均价  
                    dashStyle: 'ShortDash'    
                },{ // mark the weekend    
                    color: 'red',    
                    width: 2,    
                    value: <%= @charts_x_data.length() -1  %>,    //最高报价
                    dashStyle: 'ShortDash'    
                }]  
                 
            }, 
            tooltip: {
	            valueDecimals: 2, //小数位精度
	            valuePrefix: '¥', //前缀
	            formatter: function() {
                //修改默认弹层的样式,默认为x,y值
                if (this.point.zindex == "x"){
                  return false   
                }
                s = "";
                s += this.series.name + ": ¥" + this.y + "<br/>";
                for(var x in data_info[this.point.zindex]){
                    s += x + ": " + data_info[this.point.zindex][x] + "<br/>"
                }
                for(var x in attr_value_data[this.point.zindex]){
                    s += x + ": " + attr_value_data[this.point.zindex][x] + "<br/>"
                }
    	           return s;
		          }
        	},
            series: [{    
                data: <%= raw @series_data %> ,
                name: "品牌价"
            }]  
                 
        });    
    });    
</script>

 

 

你可能感兴趣的:(tooltip,highchart)