2017-06-27 5 views
1

これを説明する手間がかかりますので、私にご負担ください。 ハイチャート - チャートをドリルダウンするときにテキストボックスの値を変更します

私はHighchartsで作成され、この大規模なツリーマップがあります。

http://jsfiddle.net/mb3hu1px/2/

var data = { 
 
    "ARS": { 
 
     "01To03Years": { 
 
     "N": { 
 
      "ARGENTINA": 951433 
 
     } 
 
     }, 
 
     "Above05Years": { 
 
     "N": { 
 
      "ARGENTINA": 3719665 
 
     } 
 
     } 
 
    }, 
 
    "CNY": { 
 
     "03To05Years": { 
 
     "N": { 
 
      "CHINA": 162950484 
 
     } 
 
     } 
 
    }, 
 
    "COP": { 
 
     "Above05Years": { 
 
     "N": { 
 
      "COLOMBIA": 323390000 
 
     } 
 
     } 
 
    }, 
 
    "EUR": { 
 
     "01To03Years": { 
 
     "Y": { 
 
      "BELGIUM": 393292575 
 
     } 
 
     } 
 
    } 
 
    }, 
 
    points = [], 
 
    currencyPoints, 
 
    currencyVal, 
 
    currencyI = 0, 
 
    periodPoints, 
 
    periodI, 
 
    yesOrNoPoints, 
 
    yesOrNoI, 
 
    currency, 
 
    period, 
 
    yesOrNo, 
 
    mil, 
 
    causeMil, 
 
    causeMilI, 
 
    causeName = { 
 
    'N': 'Country Name', 
 
    'Y': 'Country Name' 
 
    }; 
 

 
for (currency in data) { 
 
    if (data.hasOwnProperty(currency)) { 
 
    currencyVal = 0; 
 
    currencyPoints = { 
 
     id: 'id_' + currencyI, 
 
     name: currency, 
 
     color: Highcharts.getOptions().colors[currencyI] 
 
    }; 
 

 
    periodI = 0; 
 

 
    for (period in data[currency]) { 
 
     if (data[currency].hasOwnProperty(period)) { 
 
     periodPoints = { 
 
      id: currencyPoints.id + '_' + periodI, 
 
      name: period, 
 
      parent: currencyPoints.id 
 
     }; 
 
     points.push(periodPoints); 
 
     yesOrNoI = 0; 
 

 
     for (yesOrNo in data[currency][period]) { 
 
      if (data[currency][period].hasOwnProperty(yesOrNo)) { 
 

 
      yesOrNoPoints = { 
 
       id: periodPoints.id + '_' + yesOrNoI, 
 
       name: yesOrNo, 
 
       parent: periodPoints.id, 
 
      }; 
 
      causeMilI = 0; 
 

 
      for (mil in data[currency][period][yesOrNo]) { 
 
       if (data[currency][period][yesOrNo].hasOwnProperty(mil)) { 
 
       
 
       causeMil = { 
 
        id: yesOrNoPoints.id + '_' + causeMilI, 
 
        name: mil, 
 
        parent: yesOrNoPoints.id, 
 
        value: Math.round(+data[currency][period][yesOrNo][mil]) 
 
       }; 
 
       currencyVal += causeMil.value; 
 
       points.push(causeMil); 
 
       causeMilI = causeMilI + 1; 
 
       } 
 
      } 
 

 
      points.push(yesOrNoPoints); 
 
      yesOrNoI = yesOrNoI + 1; 
 
      } 
 
     } 
 

 
     periodI = periodI + 1; 
 
     } 
 
    } 
 

 
    currencyPoints.value = Math.round(currencyVal/periodI); 
 
    points.push(currencyPoints); 
 
    currencyI = currencyI + 1; 
 
    } 
 
} 
 

 
Highcharts.chart('container', { 
 
    series: [{ 
 
    type: 'treemap', 
 
    layoutAlgorithm: 'squarified', 
 
    allowDrillToNode: true, 
 
    animationLimit: 1000, 
 
    dataLabels: { 
 
     enabled: false 
 
    }, 
 
    levelIsConstant: false, 
 
    levels: [{ 
 
     level: 1, 
 
     dataLabels: { 
 
     enabled: true 
 
     }, 
 
     borderWidth: 3 
 
    }], 
 
    data: points 
 
    }], 
 
    title: { 
 
    text: '' 
 
    } 
 
});
#container { 
 
    min-width: 300px; 
 
    max-width: 600px; 
 
    margin: 0 auto; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://code.highcharts.com/highcharts.js"></script> 
 
<script src="https://code.highcharts.com/modules/heatmap.js"></script> 
 
<script src="https://code.highcharts.com/modules/treemap.js"></script> 
 
<div id="container"></div> 
 

 
<textarea name="text" id="text" cols="30" rows="10"></textarea>

をそして、あなたが見ることができるようにも下にテキスト領域があります。

私が欲しいのは、チャート上でクリックされたすべてのレベルで、テキストエリアがいくつかのランダムなテキストで更新されます。

だから、最初のドリルダウンで、たとえば、テキスト領域は、文字通りレベル1と、第2のドリルダウンの印刷レベルをプリントアウトすることができ2などなど

誰もが私の端から何かを必要とする場合は、私を聞かせてください知っている。

多くのありがとう:)

+0

私はtreemapチャートの場合にxAxis.setExtremesを使うことができるはずだと思います:http://jsfiddle.net/mb3hu1px/4/ –

+0

これはすごくうまくいく - ありがとうGrzegorz – GBT97

答えて

0

これはいくつかの方法で実行できます。 plotOptions.series.point.events.clickでそれを行う方法です。あなたがする必要があるのは、ポイントのクリックをキャプチャしてテキストをレンダリングすることです。どのテキストを表示するか説明していないので、クリックされたポイントのプロパティnamevaluetextareaが更新されます。

Highcharts.chart('container', { 
    series: [{ 
     point: { 
     events: { 
      click: function() { 
      var thePointName = this.name, 
        thePointValue = this.value; 
      $('#text').val(function(_, val) { 
       return 'Category: ' + thePointName + ', value: ' + thePointValue; 
      }); 
      } 
     } 
     }, 
     type: 'treemap', 
     layoutAlgorithm: 'squarified', 
     allowDrillToNode: true, 
     animationLimit: 1000, 
     dataLabels: { 
     enabled: false 
     }, 
     levelIsConstant: false, 
     levels: [{ 
     level: 1, 
     dataLabels: { 
      enabled: true 
     }, 
     borderWidth: 3 
     }], 
     data: points 
    }], 
    title: { 
     text: '' 
    } 
    }); 

ライブexample

関連する問題