【问题标题】:How to align lines marker in middle/centre of the bars - High Charts如何对齐条形中间/中心的线条标记 - 高图表
【发布时间】:2018-10-04 13:48:22
【问题描述】:

线条标记需要以条为中心。

附上工作sn-p供参考

Highcharts.chart('container', {
          chart: {
            zoomType: 'false',
            height: '274px'
          },
          title: {
            text: ''
          },
          colors: ['#f47a42', '#f4418c', '#028fcf', '#000000', '#f39200'],
          subtitle: {
            text: ''
          },
          xAxis: {
            categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
            crosshair: true,
            min: 0,
          },
          yAxis: {
            min: 0,
            title: {
              text: ''
            }
          },
          tooltip: {},
          plotOptions: {
            column: {
              pointPadding: 0,
              borderWidth: 0
            }
          },
          series: [{
            type: 'column',
            name: 'XYZ',
            data: [346, 336, 436, 504, 740, 902, 735, 815, 866, 763, 742, 496],
            events: {
              legendItemClick: function (event) {
                this.visible ?
                  this.chart.get('XYZ').hide() :
                  this.chart.get('XYZ').show();
              }
            }

          }, {
            showInLegend: false,
            type: 'line',
            name: 'XYZ',
            id: 'XYZ',
            data: [346, 336, 436, 504, 740, 902, 735, 815, 866, 763, 742, 496]

          }, {
            type: 'column',
            name: ' ABC',
            data: [250, 311, 457, 571, 701, 716, 760, 815, 876],
            events: {
              legendItemClick: function (event) {
                this.visible ?
                  this.chart.get('ABC').hide() :
                  this.chart.get('ABC').show();
              }
            }

          }, {
            showInLegend: false,
            type: 'line',
            name: 'ABC',
            id: 'ABC',
            data: [250, 311, 457, 571, 701, 716, 760, 815, 876]

          }
          ],
          credits: {
            enabled: false
          },
        });
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container"></div>

【问题讨论】:

    标签: javascript jquery svg charts highcharts


    【解决方案1】:

    您可以在'line'系列上设置pointPlacement属性值正确:

    series: [{
        type: 'column',
        name: 'XYZ',
        data: [346, 336, 436, 504, 740, 902, 735, 815, 866, 763, 742, 496],
        events: {
            legendItemClick: function(event) {
                if (this.visible) {
                    this.chart.get('XYZ').hide();
                    this.chart.get('ABC').update({
                        pointPlacement: 0
                    }, false);
                } else {
                    this.chart.get('ABC').update({
                        pointPlacement: 0.15
                    }, false);
                    this.chart.get('XYZ').show();
                }
            }
        }
    
    }, {
        showInLegend: false,
        pointPlacement: -0.15,
        type: 'line',
        name: 'XYZ',
        id: 'XYZ',
        data: [346, 336, 436, 504, 740, 902, 735, 815, 866, 763, 742, 496]
    
    }, {
        type: 'column',
        name: ' ABC',
        data: [250, 311, 457, 571, 701, 716, 760, 815, 876],
        events: {
            legendItemClick: function(event) {
                if (this.visible) {
                    this.chart.get('ABC').hide();
                    this.chart.get('XYZ').update({
                        pointPlacement: 0
                    }, false);
                } else {
                    this.chart.get('XYZ').update({
                        pointPlacement: -0.15
                    }, false);
                    this.chart.get('ABC').show();
                }
            }
        }
    }, {
        showInLegend: false,
        pointPlacement: 0.15,
        type: 'line',
        name: 'ABC',
        id: 'ABC',
        data: [250, 311, 457, 571, 701, 716, 760, 815, 876]
    }],
    

    现场演示:http://jsfiddle.net/BlackLabel/08efmc49/

    【讨论】:

    • 感谢您的宝贵回答对我来说很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    相关资源
    最近更新 更多