highcharts 图表.移动条更新不正确

kg7wmglp  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(193)

我有一个用新数据更新的图表,如果配置“几乎”相同(新的副标题,数据略有不同,等等...但相同数量的数据值),我发现最后一个条形被移到了第一个条形的顶部,覆盖了它。让我感到困惑。我使用的是9.3.3,但在这个jsfiddle的“当前”中复制了它:
https://jsfiddle.net/wxpe6v2r/28/

const chart = Highcharts.chart('container', {
     "title": {
         "text": "Top 10"
     },
     "subtitle": {
         "text": "Everything",
         "useHTML": true
     },
     "colors": [
         "#F5827A",
         "#FBB3AF"
     ],
     "chart": {
         "marginLeft": 60,
         "marginRight": 60,
         "spacingTop": 10,
         "spacingRight": 0,
         "spacingBottom": 8,
         "spacingLeft": 10,
         "zoomType": "",
         "alignTicks": false,
         "animation": true
     },
     "plotOptions": {
         "series": {
             "animation": true,
             "shadow": false,
             "borderWidth": 0,
             "marker": {
                 "enabled": true,
                 "states": {
                     "hover": {
                         "enabled": false
                     }
                 }
             }
         }
     },
     "legend": {
         "enabled": true
     },
     "series": [
         {
             "name": "Count",
             "type": "column",
             "data": [
                 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9
             ]
         },
         {
             "name": "Cumulative Percent",
             "yAxis": 1,
             "type": "line",
             "data": [
                 18.18, 22.73, 27.27, 31.82, 36.36, 40.91, 45.45, 50, 54.55, 59.09, 100
             ]
         }
     ],
     "xAxis": {
         "type": "category",
         "title": {
             "text": "File",
             "enabled": false,
         },
         "categories": [
             "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "Other"
         ]
     },
     "yAxis": [
         {
             "min": 0,
             "max": 9,
             "lineWidth": 1,
             "allowDecimals": false,
             "title": {
                 "text": "Count",
                 "rotation": 270,
                 "style": {
                     "fontWeight": "bold"
                 }
             },
             "labels": {
                 "enabled": true
             },
             "startOnTick": false,
             "endOnTick": false
         },
         {
             "min": 0,
             "max": 100,
             "gridLineWidth": 0,
             "lineWidth": 1,
             "opposite": true,
             "title": {
                 "text": "Cumulative Percent",
                 "rotation": 270,
                 "style": {
                     "fontWeight": "bold"
                 }
             },
             "labels": {
                 "enabled": true,
             }
         }
     ],
});

document.getElementById('update').addEventListener('click', () => {
 chart.update({
     "title": {
         "text": "Top 10"
     },
     "subtitle": {
         "text": "Everything",
         "useHTML": true
     },
     "colors": [
         "#F5827A",
         "#FBB3AF"
     ],
     "chart": {
         "marginLeft": 60,
         "marginRight": 60,
         "spacingTop": 10,
         "spacingRight": 0,
         "spacingBottom": 8,
         "spacingLeft": 10,
         "zoomType": "",
         "alignTicks": false,
         "animation": true
     },
     "plotOptions": {
         "series": {
             "animation": true,
             "shadow": false,
             "borderWidth": 0,
             "marker": {
                 "enabled": true,
                 "states": {
                     "hover": {
                         "enabled": false
                     }
                 }
             }
         }
     },
     "legend": {
         "enabled": true
     },
     "series": [
         {
             "name": "Count",
             "type": "column",
             "data": [
                 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11
             ]
         },
         {
             "name": "Cumulative Percent",
             "yAxis": 1,
             "type": "line",
             "data": [
                 18.18, 22.73, 27.27, 31.82, 36.36, 40.91, 45.45, 50, 54.55, 59.09, 100
             ]
         }
     ],
     "xAxis": {
         "type": "category",
         "categories": [
             "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "Other"
         ]
     },
     "yAxis": [
         {
             "min": 0,
             "max": 11,
             "lineWidth": 1,
             "allowDecimals": false,
             "title": {
                 "text": "Count",
                 "rotation": 270,
                 "style": {
                     "fontWeight": "bold"
                 }
             },
             "labels": {
                 "enabled": true
             },
             "startOnTick": false,
             "endOnTick": false
         },
         {
             "min": 0,
             "max": 100,
             "gridLineWidth": 0,
             "lineWidth": 1,
             "opposite": true,
             "title": {
                 "text": "Cumulative Percent",
                 "rotation": 270,
                 "style": {
                     "fontWeight": "bold"
                 }
             },
             "labels": {
                 "enabled": true,
             }
         }
     ],
 }
);
});

只需点击更新按钮,“其他”栏将移动到第一个位置,覆盖“A”栏。
如果你对我做错了什么有任何建议,我将不胜感激。
P.S.我在使用jsfiddle后注意到,它会将条形移动到第一个匹配的序列[0]数据值。也就是说,给定序列[0]的[4,1,1,1,1,1,1,1,1,9],它会更新为[4,1,1,1,1,1,1,1,1,1,1,11]。它将[10]条(值11)放在[0]条(值4)上。如果我将初始序列[0]的值更改为[5,2,1,1,1,1,1,1,1,9],在update()时,它将值11条移动到序列[2],第一个匹配的值。我不明白。

yqlxgs2m

yqlxgs2m1#

定义xAxis.categories而不定义xAxis.type就足够了,它解决了这个问题。
但是,这个问题看起来像是一个bug,所以你可以在Highcharts Github上报告它:https://github.com/highcharts/highcharts/issues

"xAxis": {
    // "type": "category",
    "title": {
      "text": "File",
      "enabled": false,
    },
    "categories": [
      "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "Other"
    ]
  }

现场演示:https://jsfiddle.net/BlackLabel/8nu9x6g5/
API参考:https://api.highcharts.com/highcharts/xAxis.categories

相关问题