2017-05-23 8 views
0

配列値をデータとして追加し、RGraphの一部にラベルを付けたいと思います。今度は以下のようにハードコードされています。私はそれが「データ」の部分だとして「ChartData1」配列からラベルとデータの両方を抽出するためにどのようにグラフ化する「ラベル」と、残りの一部としてRGraphのデータ部分にjavascript配列を追加するには

<script type="text/javascript"> 

    var ChartData1 = new Array(); 
    var ChartData1ValueX = new Array(); 

    function ShowChart() 
    { 
    ChartData1.Add("June,100,200,300"); 
    ChartData1.Add("July,500,600,700"); 
    var totalBars1 = ChartData1.length; 
    for (var i = 0; i < totalBars1; i++) 
    { 
    var arrVal = ChartData1[i].split(","); 
    ChartData1ValueX[i] = arrVal[0]; 
    } 
     new RGraph.Bar({ 
        id: 'cvs', 
        data: [ [100, 200, 300], [500, 600, 700]], 
        labels: [ 
         'June', '', 
         'July', ''], 
        options: { 
         key: ['aa ', 'bb ', 'cc '], 
         keyPosition: 'gutter', 
         keyPositionY: 325, 
         gutterBottom: 340, 
         keyTextColor: '#ffffff', 
         unitsPost: '.00', 
         colors: ['#009900', '#005ce6', '#ff4000'],      
         title: 'Month', 
         titleYaxis: 'Total' 

        } 
       }).grow({ frames: 60 }); 
      } 

を配列(ChartData1)の数ヶ月を渡したいですか?

答えて

0

を変数に置き換えることができます使用できる:

<script> 
    // The source data 
    var source = new Array(); 
    source.push("June,100,200,300"); 
    source.push("July,500,600,700"); 
    source.push("August,500,600,700"); 
    source.push("September,300,800,200"); 
    source.push("October,300,300,500"); 
    source.push("November,600,800,300"); 

    // Array that we'll add the data and labels to 
    var labels = new Array(); 
    var data = new Array(); 

    function showChart() 
    { 
     // Loop thru the source data 
     for (var i=0; i<source.length; i++) { 

      var values = source[i].split(","); 

      // Use the first value of the string that has just been split 
      // into an array as the label 
      labels.push(values[0]); 

      // Use the remaining values as the data (to a stacked/grouped 
      // chart for example 
      var arr = [ 
       parseFloat(values[1]), 
       parseFloat(values[2]), 
       parseFloat(values[3]) 
      ]; 

      // Add the array to the data that we'll pass to the 
      // chart. 
      data.push(arr); 
     } 

     // TODO Create chart here using the data and labels arrays 
     console.log(data); 
     console.log(labels); 
    } 


    showChart(); 
</script> 
0

あなたはそれが配列を操作し、RGraph新しいもののカップルを作成するだけの場合だ配列変数を作成して、月のリストをプッシュすると、グラフのデータに

var months = []; 
    months.push("January"); 
    months.push("February"); 

    new RGraph.Bar({ 
         id: 'cvs', 
         data: [ [100, 200, 300], [500, 600, 700]], 
         labels: months, 
options: { 
         key: ['aa ', 'bb ', 'cc '], 
         keyPosition: 'gutter', 
         keyPositionY: 325, 
         gutterBottom: 340, 
         keyTextColor: '#ffffff', 
         unitsPost: '.00', 
         colors: ['#009900', '#005ce6', '#ff4000'],      
         title: 'Month', 
         titleYaxis: 'Total' 

        } 
       }).grow({ frames: 60 }); 
      } 
関連する問題