2017-06-15 70 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

相关问题