2014-02-17 83 views
2

我有一张图表,比较了多年来两个人的布尔数据。Highcharts - 分类y轴的标签放置位置

下面的jsfiddle代表我需要的东西,除了我需要底部轴上的标签与红色和绿色块的中心对齐,并且没有5出现在最右边的刻度上。

http://jsfiddle.net/zzella/Xa46f/3/

任何人有任何想法如何实现这一点对于上面的图表,或者有更好的方式来组织数据,以获得我需要的结果吗?

$(function() { 
$('#container').highcharts({ 
    credits: { 
     enabled: false 
    }, 
    exporting: { 
     enabled: false 
    }, 
    chart: { 
     type: 'bar' 
    }, 
    title: { 
     text: 'Action completed for year (Yes/No)' 
    }, 
    xAxis: { 
     categories: ['Person 1', 'Person 2'], 
     labels: { 
      align: 'left', 
      style: { 
       fontSize: '13px', 
       fontFamily: 'Arial' 
      }, 
      y: -45, 
      x: 60 
     }, 
     lineColor: '#FFFFFF', 
     tickColor: '#FFFFFF', 

    }, 
    yAxis: { 
     type: 'category', 
     categories: ["2010","2011","2012","2013", "2014"], 
     title: false, 
     lineColor: '#FFFFFF', 
     tickColor: '#FFFFFF', 
     gridLineColor: '#FFFFFF', 
    }, 
    legend: false, 
    plotOptions: { 
     bar: { 
      stacking: 'normal', 
      dataLabels: { 
       enabled: true, 
       color: '#FFFFFF', 
       align: 'center', 
       style: { 
        fontSize: '13px', 
        fontFamily: 'Verdana, sans-serif', 
        textShadow: '0 0 3px black' 
       }, 
       formatter: function() { 
        console.log(this); 
        return this.key 
       } 
      }, 
     }, 
    }, 
    series: [{ 
     name: '2014', 
     data: [{ 
      name: "2014: no", 
      color: "#a50000", 
      y: 1 
     }, { 
      name: "2014: yes", 
      color: "#006500", 
      y: 1 
     }], 

    }, { 
     name: '2013', 
     data: [{ 
      name: "2013: yes", 
      color: "#006500", 
      y: 1 
     }, { 
      name: "2013: yes", 
      color: "#006500", 
      y: 1 
     }] 
    }, { 
     name: '2012', 
     data: [{ 
      name: "2012: yes", 
      color: "#006500", 
      y: 1 
     }, { 
      name: "2012: no", 
      color: "#a50000", 
      y: 1 
     }] 
    }, { 
     name: '2011', 
     data: [{ 
      name: "2011: no", 
      color: "#a50000", 
      y: 1 
     }, { 
      name: "2011: yes", 
      color: "#006500", 
      y: 1 
     }] 
    }, { 
     name: '2010', 
     data: [{ 
      name: "2010: no", 
      color: "#a50000", 
      y: 1 
     }, { 
      name: "2010: no", 
      color: "#a50000", 
      y: 1 
     }] 
    }] 
}); 
}); 

回答

1

个等待实现,这是通过添加标签格式,以您的yAxis,像你这样你xAxis。如果您添加labels: { x: 40 },标签将沿着方框居中。

要摆脱随机5,你可以做showLastLabel: false

下面是最终yAxis,做你所描述的:

yAxis: { 
    type: 'category', 
    categories: ["2010","2011","2012","2013", "2014"], 
    title: false, 
    lineColor: '#FFFFFF', 
    tickColor: '#FFFFFF', 
    gridLineColor: '#FFFFFF', 
    labels: { 
     x: 40 
    }, 
    showLastLabel: false 
}, 

Link to the Fiddle