2013-12-19 3 views
1

도와주세요. 1 주일 동안 벽에 머리를 두드려서 줄을 서면서 행운을 찾을 수있는 모든 옵션을 시도했습니다 ...다중 시리즈 하이 차트에 json 데이터로드

C#/Razor/WebMatrix 사이트에서 HighCharts를 사용하고 있습니까? 누적 세로 막 대형 차트를 만들려고합니다. 동적으로 내 카테고리를로드해야하지만 시리즈를로드 할 수 없습니다.

저는 자바 스크립트와 웹 프로그래밍에 처음으로 익숙해졌습니다. 친절하게 대해주십시오!

json으로 리턴 데이터가 : 나는 차트를 렌더링하기 전에 일련의 데이터를로드하려고

["Clubs","1850","2600","5600","4950","8535","6050","8640", 
"Fesitvals","0","0","1000","750","0","1500","3250", 
"Private","650","2300","1600","2500","0","400","900", 
"Weddings","0","1400","3600","0","0","0","0", 
"Other Income","0","0","70","540","50","0","0"] 

... 다음은 서식 전체 스크립트 등

스크립트입니다 Json 데이터 세트를 처리하고로드하는 함수를 폭탄 처리합니다. (굵게/기울임 꼴 참조). 차트 멋지다 경우 하드 코드 시리즈 데이터,하지만 사이트가 데이터베이스 기반이며 데이터가 여기에 .... 정기적으로

을 변경하는 스크립트입니다 이후 :

$(function() { 
    var ChartType = document.getElementById("CType").value; 
    var SelectMember = document.getElementById("SMbmr").value; 
    Highcharts.theme = { 

     chart: { 
      backgroundColor: { 
       linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
       stops: [ 
      [0, 'rgb(0, 0, 0'], 
      [1, 'rgb(0, 0, 0)'] 
     ] 
      }, 
      borderWidth: 0, 
      borderRadius: 15, 
      plotBackgroundColor: null, 
      plotShadow: false, 
      plotBorderWidth: 0 
     }, 
     title: { 
      style: { 
       color: '#FFF', 
       font: '16px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' 
      } 
     }, 
     subtitle: { 
      style: { 
       color: '#DDD', 
       font: '12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' 
      } 
     }, 
     xAxis: { 
      gridLineWidth: 0, 
      lineColor: '#999', 
      tickColor: '#999', 
      labels: { 
       style: { 
        color: '#999', 
        fontWeight: 'bold' 
       } 
      }, 
      title: { 
       style: { 
        color: '#AAA', 
        font: 'bold 12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' 
       } 
      } 
     }, 
     yAxis: { 
      alternateGridColor: null, 
      minorTickInterval: null, 
      gridLineColor: 'rgba(255, 255, 255, .1)', 
      minorGridLineColor: 'rgba(255,255,255,0.07)', 
      lineWidth: 0, 
      tickWidth: 0, 
      labels: { 
       style: { 
        color: '#999', 
        fontWeight: 'bold' 
       } 
      }, 
      title: { 
       style: { 
        color: '#AAA', 
        font: 'bold 12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' 
       } 
      } 
     }, 
     legend: { 
      itemStyle: { 
       color: '#CCC' 
      }, 
      itemHoverStyle: { 
       color: '#FFF' 
      }, 
      itemHiddenStyle: { 
       color: '#333' 
      } 
     }, 
     labels: { 
      style: { 
       color: '#CCC' 
      } 
     }, 
     tooltip: { 
      backgroundColor: { 
       linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
       stops: [ 
      [0, 'rgba(96, 96, 96, .8)'], 
      [1, 'rgba(16, 16, 16, .8)'] 
     ] 
      }, 
      borderWidth: 0, 
      style: { 
       color: '#FFF' 
      } 
     }, 


     plotOptions: { 
      series: { 
       shadow: true 
      }, 
      line: { 
       dataLabels: { 
        color: '#CCC' 
       }, 
       marker: { 
        lineColor: '#333' 
       } 
      }, 
      spline: { 
       marker: { 
        lineColor: '#333' 
       } 
      }, 
      scatter: { 
       marker: { 
        lineColor: '#333' 
       } 
      }, 
      candlestick: { 
       lineColor: 'white' 
      } 
     }, 

     toolbar: { 
      itemStyle: { 
       color: '#CCC' 
      } 
     }, 

     navigation: { 
      buttonOptions: { 
       symbolStroke: '#DDDDDD', 
       hoverSymbolStroke: '#FFFFFF', 
       theme: { 
        fill: { 
         linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
         stops: [ 
        [0.4, '#606060'], 
        [0.6, '#333333'] 
       ] 
        }, 
        stroke: '#000000' 
       } 
      } 
     }, 

     // scroll charts 
     rangeSelector: { 
      buttonTheme: { 
       fill: { 
        linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
        stops: [ 
       [0.4, '#888'], 
       [0.6, '#555'] 
      ] 
       }, 
       stroke: '#000000', 
       style: { 
        color: '#CCC', 
        fontWeight: 'bold' 
       }, 
       states: { 
        hover: { 
         fill: { 
          linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
          stops: [ 
        [0.4, '#BBB'], 
        [0.6, '#888'] 
        ] 
         }, 
         stroke: '#000000', 
         style: { 
          color: 'white' 
         } 
        }, 
        select: { 
         fill: { 
          linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
          stops: [ 
        [0.1, '#000'], 
        [0.3, '#333'] 
        ] 
         }, 
         stroke: '#000000', 
         style: { 
          color: 'yellow' 
         } 
        } 
       } 
      }, 
      inputStyle: { 
       backgroundColor: '#333', 
       color: 'silver' 
      }, 
      labelStyle: { 
       color: 'silver' 
      } 
     }, 

     navigator: { 
      handles: { 
       backgroundColor: '#666', 
       borderColor: '#AAA' 
      }, 
      outlineColor: '#CCC', 
      maskFill: 'rgba(16, 16, 16, 0.5)', 
      series: { 
       color: '#7798BF', 
       lineColor: '#A6C7ED' 
      } 
     }, 

     scrollbar: { 
      barBackgroundColor: { 
       linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
       stops: [ 
       [0.4, '#888'], 
       [0.6, '#555'] 
      ] 
      }, 
      barBorderColor: '#CCC', 
      buttonArrowColor: '#CCC', 
      buttonBackgroundColor: { 
       linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
       stops: [ 
       [0.4, '#888'], 
       [0.6, '#555'] 
      ] 
      }, 
      buttonBorderColor: '#CCC', 
      rifleColor: '#FFF', 
      trackBackgroundColor: { 
       linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, 
       stops: [ 
      [0, '#000'], 
      [1, '#333'] 
     ] 
      }, 
      trackBorderColor: '#666' 
     }, 

     // special colors for some of the demo examples 
     legendBackgroundColor: 'rgba(48, 48, 48, 0.8)', 
     legendBackgroundColorSolid: 'rgb(70, 70, 70)', 
     dataLabelsColor: '#444', 
     textColor: '#E0E0E0', 
     maskColor: 'rgba(255,255,255,0.3)' 
    }; 

    // Apply the theme 
    var highchartsOptions = Highcharts.setOptions(Highcharts.theme); 
    var CatName = new Array(); 
    var DataSeries = new Array(); 
    var currentDate = new Date(); 
    var currentYear = currentDate.getFullYear(); 
    for (var i = 2007; i <= currentYear; i++) { 
     CatName.push(i.toString()); 
    } 
    ***$.getJSON('/Admin/Accounting/ChartJSon/' + ChartType + '/0', function (DataSet) { 
      options.series = DataSet; 
    });*** 
    $('#container').highcharts(
     { 

      chart: 
      { 
       renderTo: 'container', 
       defaultSeriesType: 'column', 
       plotBorderWidth: 1, 
       plotBorderColor: '#3F4044' 
      }, 
      credits: { enabled: false }, 
      title: 
      { 
       text: 'Sales by Type and Year' 
      }, 

      xAxis: 
      { 
       categories: CatName 
      }, 

      yAxis: 
      { 
       allowDecimals: false, 
       min: 0, 
       title: 
       { 
        text: 'Sales' 
       } 
      }, 

      tooltip: 
      { 
       formatter: function() { 
        return '<b>' + this.x + '</b><br/>' + 
         this.series.name + ': ' + this.y + '<br/>' + 
         'Total: ' + this.point.stackTotal; 
       } 
      }, 

      plotOptions: 
      { 
       column: 
       { 
        stacking: 'normal' 
       } 
      }, 

      series: [] 
     }); 

}); 
+0

JSFiddle이 있습니까? http://jsfiddle.net/ –

답변

0

그럼 내가 여기에 몇 가지 문제를 참조하십시오. 우선 하이 차트 코드를 아래에 언급 된 코드로 대체하십시오. 시리즈 옵션에서 각 시리즈에 대한 데이터를 지정해야합니다. 고유 한 이름을 제공하십시오.

$('#container').highcharts(
       { 

        chart: 
        { 
         renderTo: 'container', 
         defaultSeriesType: 'column', 
         plotBorderWidth: 1, 
         plotBorderColor: '#3F4044' 
        }, 
        credits: { enabled: false }, 
        title: 
        { 
         text: 'Sales by Type and Year' 
        }, 

        xAxis: 
        { 
         categories: CatName 
        }, 

        yAxis: 
        { 
         allowDecimals: false, 
         min: 0, 
         title: 
         { 
          text: 'Sales' 
         } 
        }, 

        tooltip: 
        { 
         formatter: function() { 
          return '<b>' + this.x + '</b><br/>' + 
           this.series.name + ': ' + this.y + '<br/>' + 
           'Total: ' + this.point.stackTotal; 
         } 
        }, 

        plotOptions: 
        { 
         column: 
         { 
          stacking: 'normal' 
         } 
        }, 

        series: [{ 
         name: 'Clubs', 
         data: [] 
        }, { 
         name: 'Festivals', 
         data: [] 
        }, { 
         name: 'Private', 
         data: [], 
        }, { 
         name: 'Weddings', 
         data: [], 
        }, { 
         name: 'OtherIncome', 
         data: [], 
        }] 
       }); 

     }); 

그리고 JSON은 숫자로만 구성된 배열이어야합니다. 당신이 차트를 초기화하려고하기 때문에

0
  1. 차트 초기화 insie해서 getJSON 본문에 앞서 다음 데이터는 숫자가 아닌 문자열을 사용할 필요가 JSON에서 URL
  2. 에서 얻을 수있다한다. 가능성이 없다면 각 데이터 값에 대해 parseFloat를 사용하여 javascript의 값을 파싱해야합니다.
  3. 시리즈 데이터 객체입니다 (숫자 만 변경해야하며 "Fesitvals"와 같은 이름이 아님). 몇 개의 시리즈가 있고 각자 자신의 이름이 있다면, json과 praaper의 정확한 배열 구조를 파싱해야합니다.
+0

내가 말했듯이이 초보자라면 초보자이기 때문에 # 2와 # 3에서 무슨 말을하는지 명확하지 않습니다. 시리즈 이름, 시리즈 수는 다양하므로 Saumil에서 제안한 하드 코딩은 실행 가능하지 않습니다. 시리즈 이름으로 첫 번째 배열 요소를 추출하고 나머지 배열 요소를 시리즈로 추출 할 수있는 방법이 있습니까? – user3117622

+0

JSon에서 $ Each를 수행 한 다음 첫 번째 요소를 시리즈 이름으로 이동하고 나머지 요소를 다른 배열로 다시 포맷 한 다음 시리즈로 밀어 넣을 필요가 있습니까? – user3117622

+0

그래서 처음에는 자바 스크립트에 익숙한 조언 –