2014-04-07 4 views
1

방금 ​​하이 차트를 사용하기 시작했습니다. 여기에 붙어 있습니다. -하이 차트에 배열을 전달하는 방법 ??

데이터베이스에서 가져 오는 js_platform, js_totalTest이라는 배열이 2 개 있습니다.

차트를 생성하는 코드는 - 내가 js_totalTest의 배열 값을 보낼 시리즈 이제

<!DOCTYPE html> 
    <body> 
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> 
    <script src="http://code.highcharts.com/highcharts.js"></script> 
    <script src="http://code.highcharts.com/modules/exporting.js"> </script> 
    <script> 
$(function() { 
    js_platform = <?php echo json_encode($platform); ?>; 
    js_totalTest = <?php echo json_encode($totalTest); ?>; 
     $('#container').highcharts({ 
      chart: { 
       type: 'column' 
      }, 
      title: { 
       text: 'Overall avalibility of testcases on each platform' 
      }, 
      xAxis: { 
       categories: js_platform 
      }, 
      yAxis: { 
       min: 0, 
       title: { 
        text: 'Total fruit consumption' 
       }, 
       stackLabels: { 
        enabled: true, 
        style: { 
         fontWeight: 'bold', 
         color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray' 
        } 
       } 
      }, 
      legend: { 
       align: 'right', 
       x: -70, 
       verticalAlign: 'top', 
       y: 20, 
       floating: true, 
       backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white', 
       borderColor: '#CCC', 
       borderWidth: 1, 
       shadow: false 
      }, 
      tooltip: { 
       formatter: function() { 
        return '<b>'+ this.x +'</b><br/>'+ 
         this.series.name +': '+ this.y +'<br/>'+ 
         'Total: '+ this.point.stackTotal; 
       } 
      }, 
      plotOptions: { 
       column: { 
        stacking: 'normal', 
        dataLabels: { 
         enabled: true, 
         color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white', 
         style: { 
          textShadow: '0 0 3px black, 0 0 3px black' 
         } 
        } 
       } 
      }, 
      series: [{ 
       name: 'John', 
       data: [5, 3, 4, 7, 2] 
      }, { 
       name: 'Jane', 
       data: [2, 2, 3, 2, 1] 
      }, { 
       name: 'Joe', 
       data: [3, 4, 4, 2, 5] 
      }] 
     }); 
    }); 
    </script> 

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> 

</body> 
</html> 

.

여기 내가 **series: [{data: [js_totalTest]}]** 같은 것을하면 아무 것도 표시되지 않습니다.

어떻게 할 수 있습니까? 안내하십시오.

+0

을 참조하십시오. json 형식으로 시리즈 데이터를 전달해야합니다. – Gowri

+0

MM ... 네, 저는 단지 js_Toaltest의 모든 값을 직렬로 원합니다. 이 코드는 피곤하지만 작동하지 않습니다. - 'var mySeries = []; for (var i = 0; i user3496418

답변

1

이런 식으로 시도해보십시오. 배열 js_totalTest데이터이름을 시리즈

루프 배열 데이터

var arr = []; 
for(var i=0;i<js_totalTest.length;i++) 
{ 
    arr[i] = {}; 
    arr[i]['name'] = ''; //Here push your series name field in your example "John, Jane etc" 

    for(var j=0;j<s.length;j++) 
    { 
      arr_data.push(parseInt(s[j])); 
    } 
    arr[i]['data'] = parseInt('') ; // Here push your series data (Eg: 5 ,3 , etc.) 
} 

패스 arr을 포함

series: arr 
+0

안녕하세요. 'arr [i] [ 'name'] = ''; // 여기서 시리즈 이름 필드를 푸시합니다. ' arr [i] ['data '] = parseInt (' '); // 여기서 시리즈 데이터를 푸시합니다. ' – user3496418

+0

내 게시물 점검을 업데이트했습니다. 배열 형식을 인쇄하고 데이터가 어떤 방식으로 들어오는 지 체크인하십시오. – Gowri

+0

@Gowiri'echo json_encode ($ totalTest);의 출력은 다음과 같습니다 : ** [ "1", "1", "4", "193", "98", "218", "98" 「471」, 「9」, 「201」, 「18」, 「144」, 「2」, 「163」, 「30」, 「163」, 「90」, 「84」, 「397」, 「74」, 「4」, 「1」, 「1」, 「1」, 「979」, 「297」, 「264」, 「418」, 「316」, 「280」, 「6」, 「4」, 「1」, 「2」, 「9」, 「2」, 「52」, 「201」, 「80」, 「316」, 「433」, 691 ","496 ","767 ","610 ","1 ","20 "] ** – user3496418

관련 문제