我正在尝试在Chart.js中添加双Y轴,以进行两个数据集的比较。我目前正在使用Leigh Quince的LineBar扩展,这是在此处找到的答案:Chart.js how to get Combined Bar and line charts?
大约一年前,也有一个关于双Y轴的解决方案,但仅适用于线性图表,并且与Nick的主程序相差甚远。似乎只有线性和条形图表,或者双Y轴,没有同时具备两者。
我的问题在于,我需要将TSAT%(饱和度水平)表示为左Y轴线性图表,到右Y轴条形图表的铁蛋白剂量水平。这就是我需要它看起来像的样子:
(似乎Stackoverflow已经改变了它的颜色,希望您仍然可以阅读Y轴刻度)
如果有人能提供解决方案,我将非常感激。
当前代码:
我的问题在于,我需要将TSAT%(饱和度水平)表示为左Y轴线性图表,到右Y轴条形图表的铁蛋白剂量水平。这就是我需要它看起来像的样子:
(似乎Stackoverflow已经改变了它的颜色,希望您仍然可以阅读Y轴刻度)
如果有人能提供解决方案,我将非常感激。
当前代码:
var data = {
labels: ["Jun 2013", "Jul 2013","Aug 2013","Sep 2013","Oct 2013","Nov 2013","Dec 2013", "Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014", "May 2014"],
datasets: [
{
label: "TSAT",
type: "line",
fillColor: "transparent",
strokeColor: "#a33a59",
pointColor: "#a33a59",
pointHighlightStroke: "#FFF",
data:[33,32.9,32.9,33.2,33.2,33.2,32.7,32.9,32.9,32.7,32.7,32.7]
},
{
label: "Ferritin",
type: "bar",
fillColor: "#ed7141",
strokeColor: "#ed7141",
data: [939,929,949,991,992,993,976,976,973,986,972,939]
}
]
};
var options = {
responsive: true,
scaleOverride: true,
scaleSteps: 10,
scaleStepWidth: 5,
scaleStartValue: 0,
showTooltips: false,
pointDot: true,
pointDotRadius : 10,
datasetStrokeWidth : 3,
bezierCurve : false,
scaleShowLines: false,
scaleGridLineWidth : 2,
scaleGridLineColor : "#EEEEEE",
scaleLineWidth: 3,
scaleLineColor: "#000000",
scaleFontFamily: 'Gotham Book,sans-serif',
scaleFontSize: 18,
}
ctx = $("#myChart").get(0).getContext("2d");
TSATChart = new Chart(ctx).LineBar(data, options);
顺便说一句,我修改了Quince的LineBar,先绘制柱形图,然后再绘制线条。原始代码是相反的。因此,如果我成功添加了示例到jsfiddle中,我可能无法添加任何内容,但我会进行编辑并添加链接。
谢谢!