Highcharts: having trouble recreating stacked area chart from Excel with positive and negative values

前端 未结 1 1848
执念已碎
执念已碎 2021-01-06 14:04

I\'m converting a series of Excel charts into Highcharts, and came across a curious situation involving a stacked area chart with both positive and negative values.

1条回答
  •  隐瞒了意图╮
    2021-01-06 14:44

    After mulling this over the weekend, I tried adding some of the series to different groups (stacks) and was able to achieve what I wanted.

    First, I added the two topmost series from the Excel spreadsheet (series E and B in my example) to stack "I" in order from top to bottom. Then, I added the remaining series to a second stack, "II," which appears below the zero line, in order from bottom to top.

    Here's the revised series code:

    series: [
      { name: 'Total', type: 'line', data: [0,0.08,-0.31,-1.09,-1.82,-2.18,-2.49,-3.05,-3.12,-3.15] },  
      /* stack I items */
      { name: 'E', stack: 'I', data: [0,0.17794,0.31787,0.36,0.37,0.23917,0.17944,0.14766,0.05938,0.24891] }, 
      { name: 'B', stack: 'I', data: [0,0.239857,0.637651,0.733988,0.85,0.855423,0.938974,0.912378,1.017854,0.985514] }, 
      /* stack II items */
      { name: 'G', stack: 'II', data: [0,0.013198,0.055014,0.019322,0.07,0.077394,0.061947,0.010502,0.035015,-0.055604] },  
      { name: 'F', stack: 'II', data: [0,0.029755,-0.45174,-0.397836,-0.61,-0.56368,-0.593108,-0.462725,-0.351842,-0.210976] }, 
      { name: 'D', stack: 'II', data: [0,-0.098096,-0.170803,-0.688206,-0.92,-0.918492,-0.876488,-0.967249,-0.954217,-1.029596] },
      { name: 'C', stack: 'II', data: [0,-0.096543,-0.271997,-0.512372,-0.70,-0.665893,-0.723534,-0.879249,-0.890587,-0.821584] },
      { name: 'A', stack: 'II', data: [0,-0.212001,-0.409192,-0.559879,-0.81,-1.089119,-1.313719,-1.606092,-1.808868,-2.041628] }
    ]
    

    The resulting chart matches up very neatly with its Excel progenitor:

    You can find a revised fiddle here: http://jsfiddle.net/brightmatrix/fjhfxL83/

    I hope this question and answer are helpful to someone out there!

    0 讨论(0)
提交回复
热议问题