2017-06-15 67 views
0

我想結合兩種類型的圖表('scatter'和'line')具有不同的數據來源。是否可以合併來自JSON對象的數據和來自列的數據? [C3JS]

我可以單獨成功顯示它們(因此以下屏幕截圖),但不能同時顯示在一起。

ScatterLine Graphs

我的猜測是,使用data.keys的覆蓋從我的專欄來的數據的顯示,但我暫時還沒有發現有關此問題的任何東西。

var jsondata = [{ 
    "intentId": "QP3035", 
    "intentName": "lapin", 
    "confidence": 90, 
    "occurences": 150 
}, { 
    "intentId": "QP4019", 
    "intentName": "ours", 
    "confidence": 80, 
    "occurences": 140 
}, { 
    "intentId": "QP4022", 
    "intentName": "chouette", 
    "confidence": 60, 
    "occurences": 60 
}, { 
    "intentId": "QP3032 ", 
    "intentName": "cheval", 
    "confidence": 21, 
    "occurences": 120 
}, { 
    "intentId": "QP4029", 
    "intentName": "poule", 
    "confidence": 18, 
    "occurences": 17 
}]; 

jsondata = jsonfile.sort(function(a, b) { 
    return a.confidence - b.confidence; 
}); 


var test = c3.generate({ 
    bindto: '#intentsConfidenceChart', 
    data: { 
    json: jsondata, 
    keys: { 
     x: 'confidence', 
     value: ['confidence', 'occurences'] 
    }, 
    xs: { 
     graphTop: 'x1', 
     graphBot: 'x2' 
    }, 
    columns: [ 
     ['x1',20,100], 
     ['x2', 20,20,90,100,100], 
     ['graphTop',160,160], 
     ['graphBot',160,140,40,40,160] 
    ], 
    types:{ 
     occurences: 'scatter', 
     graphTop:'line', 
     graphBot:'line' 
    } 
    }, 
    axis: { 
    x: { 
     min: 0, 
     max: 100, 
     label: 'Confidence Level', 
     tick: { 
     fit: false 
     } 
    }, 
    y: { 
     label: 'Occurences' 
    } 
    }, 
    legend: { 
    show: false 
    }, 
    tooltip: { 
    contents: function(d) { 
     return jsonfile[d[0].index].intentId + ' : ' + jsonfile[d[0].index].intentName; 
    } 
    } 
}); 

(順便說一句,我畫這些圖的原因是,我想有一個敏感區識別我的圖形的某個區域,我已經開始設想這一點之前掙扎了很多與SVG黑客)。

非常感謝提前!

回答

2

我不認爲有可能混合jsondata與列直接

但是你可以將您的JSON到數組,並與其他陣列一起使用它:

data: { 
    //json: jsondata, 
    // keys: { 
    //  x: 'confidence', 
    // value: ['confidence', 'occurences'] 
    // }, 
    xs: { 
     graphTop: 'x1', 
     graphBot: 'x2', 
     confidence: 'occurences' 
    }, 
    columns: [ 
     ['x1',20,100], 
     ['x2', 20,20,90,100,100], 
     ['graphTop',160,160], 
     ['graphBot',160,140,40,40,160], 
     ["confidence", 90, 80, 60, 21, 18], 
     ["occurences", 150, 140 , 60, 120, 17] 
    ], 
+0

其實我不能因爲JSON數據,預計不久將動態加載。所以我需要擺脫剛性柱。我想我會試圖借鑑這個地區。 – Amesys

+0

如何將JSON數據轉換爲數組,然後將其放入帶有加載方法的圖表中? http://c3js.org/reference.html#api-load –

+0

我會標記我的問題解決,即使它不是我一開始就在尋找的東西。 – Amesys

相關問題