Trying to create the above using c3.js.
We are using the same charting library across the application so would like to keep it consistent. Didn't find a way in c3.js to either customize donut or pie chart to get this. i need it to be hour, instead of percentage . and also the target value should be 12 instead of 100%. Any help or pointers are greatly appreciated.
normal jsfiddle link to customise.
var chart = c3.generate({
bindto: '#pie-chart',
data: {
columns: [
['data1', 30],
['data2', 120],
],
type : 'donut',
onclick: function (d, i) { console.log("onclick", d, i); },
onmouseover: function (d, i) { console.log("onmouseover", d, i); },
onmouseout: function (d, i) { console.log("onmouseout", d, i); }
},
donut: {
title: "Iris Petal Width"
}
});
setTimeout(function () {
chart.load({
columns: [
["setosa", 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.4, 0.4, 0.3, 0.3, 0.3, 0.2, 0.4, 0.2, 0.5, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.1, 0.2, 0.2, 0.2, 0.2, 0.1, 0.2, 0.2, 0.3, 0.3, 0.2, 0.6, 0.4, 0.3, 0.2, 0.2, 0.2, 0.2],
["versicolor", 1.4, 1.5, 1.5, 1.3, 1.5, 1.3, 1.6, 1.0, 1.3, 1.4, 1.0, 1.5, 1.0, 1.4, 1.3, 1.4, 1.5, 1.0, 1.5, 1.1, 1.8, 1.3, 1.5, 1.2, 1.3, 1.4, 1.4, 1.7, 1.5, 1.0, 1.1, 1.0, 1.2, 1.6, 1.5, 1.6, 1.5, 1.3, 1.3, 1.3, 1.2, 1.4, 1.2, 1.0, 1.3, 1.2, 1.3, 1.3, 1.1, 1.3],
]
});
}, 1500);
setTimeout(function () {
chart.unload({
ids: 'data1'
});
chart.unload({
ids: 'data2'
});
}, 2500);
I think I'm pretty close to what you were wanting. The onrendered callback code is to append a circle in the middle of that; you may want to handle that another way, my implementation is pretty basic.
The key things to pay attention to are the config options under gauge:
gauge: {
fullCircle: true, // This makes it go all the way around
max: 12, // This is your max unit -- 12h
min: 0, // Min. is 0
startingAngle: 90, // This sets the opening to the other side
width: 25, // This is how thick the outer arc is.
label: {
format: function(value, ratio) {
return value + 'HR';
}
}
var chart = c3.generate({
data: {
columns: [
['data1', 10],
],
type: 'gauge',
colors: {
data1: '#9873FF'
}
},
gauge: {
fullCircle: true, // This makes it go all the way around
max: 12, // This is your max unit -- 12h
min: 0, // Min. is 0
startingAngle: 90, // This sets the opening to the other side
width: 25, // This is how thick the outer arc is
label: {
format: function(value, ratio) {
return value + 'HR';
}
}
},
onrendered: function() {
setTimeout(function(){ // timeout is needed for initial render.
var centerBBox = d3.select('.c3-arc-data1').node().getBBox();
d3.select('.c3-arcs-data1')
.insert('circle', '.c3-arc-data1')
.classed('c3-arc-data1-background', true)
.attr('cx', centerBBox.x + centerBBox.width/2)
.attr('cy', centerBBox.y + centerBBox.height/2)
.attr('fill', '#6C40E8')
.attr('r', (centerBBox.height / 2 - 25)) // "25" is an arbitrary number
}, 0);
}
});
.c3-chart-arcs-gauge-max,
.c3-chart-arcs-gauge-min,
.c3-chart-arcs-background{
display: none;
}
.c3-gauge-value {
fill: white !important;
font-family: "Lucida Console", Helvetica, sans-serif;
font-size: 40px !important;
transform: translateY(10px);
}
.c3-arc-data1 {
stroke: transparent !important;
}
<link href="https://cdn.rawgit.com/c3js/c3/0.4.11/c3.css" rel="stylesheet"/>
<script src="https://cdn.rawgit.com/c3js/c3/0.4.11/c3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<div id="chart"></div>
Related
I am trying to create a stacked column chart and trying to integrate a line chart on Y axis, Chart is rendering but line is not visible which is using opposite y axis value.
latitudeSeries should create a line chart using the opposite y axis that is Y axis value on the right side. But it's not rendering the line chart though opposite y axis is rendered.
<!-- Styles -->
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<!-- Resources -->
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
<script src="https://cdn.amcharts.com/lib/5/xy.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
<!-- Chart code -->
<script>
am5.ready(function() {
// Create root element
// https://www.amcharts.com/docs/v5/getting-started/#Root_element
var root = am5.Root.new("chartdiv");
// Set themes
// https://www.amcharts.com/docs/v5/concepts/themes/
root.setThemes([
am5themes_Animated.new(root)
]);
// Create chart
// https://www.amcharts.com/docs/v5/charts/xy-chart/
var chart = root.container.children.push(am5xy.XYChart.new(root, {
panX: false,
panY: false,
wheelX: "panX",
wheelY: "zoomX",
layout: root.verticalLayout
}));
// Add legend
// https://www.amcharts.com/docs/v5/charts/xy-chart/legend-xy-series/
var legend = chart.children.push(am5.Legend.new(root, {
centerX: am5.p50,
x: am5.p50
}));
var data = [{
"year": "2021",
"europe": 2.5,
"namerica": 2.5,
"asia": 2.1,
"lamerica": 1,
"meast": 0.8,
"africa": 0.4,
"latitude": 40.00
}, {
"year": "2022",
"europe": 2.6,
"namerica": 2.7,
"asia": 2.2,
"lamerica": 0.5,
"meast": 0.4,
"africa": 0.3,
"latitude": 45.74
}, {
"year": "2023",
"europe": 2.8,
"namerica": 2.9,
"asia": 2.4,
"lamerica": 0.3,
"meast": 0.9,
"africa": 0.5,
"latitude": 39.74
}];
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
var xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root, {
categoryField: "year",
renderer: am5xy.AxisRendererX.new(root, {
cellStartLocation: 0.1,
cellEndLocation: 0.9
}),
tooltip: am5.Tooltip.new(root, {})
}));
var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
min: 0,
renderer: am5xy.AxisRendererY.new(root, {})
}));
var latitudeAxisRenderer = am5xy.AxisRendererY.new(root, {opposite:true});
var latitudeAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
renderer: latitudeAxisRenderer
}));
var latitudeSeries = chart.series.push(am5xy.LineSeries.new(root, {
xAxis: xAxis,
yAxis: latitudeAxis,
valueYField: "latitude",
valueXField: "year",
tooltip:am5.Tooltip.new(root, {
labelText:"latitude: {valueY}"
})
}));
latitudeSeries.strokes.template.setAll({ strokeWidth: 2 });
// Add circle bullet
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/#Bullets
latitudeSeries.bullets.push(function() {
var graphics = am5.Circle.new(root, {
strokeWidth: 2,
radius: 5,
stroke: latitudeSeries.get("stroke"),
fill: root.interfaceColors.get("background"),
});
graphics.adapters.add("radius", function(radius, target) {
return target.dataItem.dataContext.townSize;
})
return am5.Bullet.new(root, {
sprite: graphics
});
});
latitudeSeries.data.setAll(data);
// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
function makeSeries(name, fieldName, stacked) {
var series = chart.series.push(am5xy.ColumnSeries.new(root, {
stacked: stacked,
name: name,
xAxis: xAxis,
yAxis: yAxis,
valueYField: fieldName,
categoryXField: "year"
}));
series.columns.template.setAll({
tooltipText: "{name}, {categoryX}:{valueY}",
width: am5.percent(90),
tooltipY: am5.percent(10)
});
xAxis.data.setAll(data);
series.data.setAll(data);
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
series.appear();
series.bullets.push(function () {
return am5.Bullet.new(root, {
locationY: 0.5,
sprite: am5.Label.new(root, {
text: "{valueY}",
fill: root.interfaceColors.get("alternativeText"),
centerY: am5.percent(50),
centerX: am5.percent(50),
populateText: true
})
});
});
legend.data.push(series);
}
makeSeries("Europe", "europe", true);
makeSeries("North America", "namerica", true);
makeSeries("Asia", "asia", true);
makeSeries("Latin America", "lamerica", true);
makeSeries("Middle East", "meast", true);
makeSeries("Africa", "africa", true);
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
chart.appear(1000, 100);
}); // end am5.ready()
</script>
<!-- HTML -->
<div id="chartdiv"></div>
Your xAxis is a category axis, not a value axis. Thus, in your latitudeSeries settings, you must use categoryXField instead of valueXField.
For more readability, I recommend you to synchronize latitudeAxis and yAxis using syncWithAxis. You should also set transparency on your column series.
I edited your code and added these little corrections (with comments).
<!-- Styles -->
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<!-- Resources -->
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
<script src="https://cdn.amcharts.com/lib/5/xy.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
<!-- Chart code -->
<script>
am5.ready(function() {
// Create root element
// https://www.amcharts.com/docs/v5/getting-started/#Root_element
var root = am5.Root.new("chartdiv");
// Set themes
// https://www.amcharts.com/docs/v5/concepts/themes/
root.setThemes([
am5themes_Animated.new(root)
]);
// Create chart
// https://www.amcharts.com/docs/v5/charts/xy-chart/
var chart = root.container.children.push(am5xy.XYChart.new(root, {
panX: false,
panY: false,
wheelX: "panX",
wheelY: "zoomX",
layout: root.verticalLayout
}));
// Add legend
// https://www.amcharts.com/docs/v5/charts/xy-chart/legend-xy-series/
var legend = chart.children.push(am5.Legend.new(root, {
centerX: am5.p50,
x: am5.p50
}));
var data = [{
"year": "2021",
"europe": 2.5,
"namerica": 2.5,
"asia": 2.1,
"lamerica": 1,
"meast": 0.8,
"africa": 0.4,
"latitude": 40.00
}, {
"year": "2022",
"europe": 2.6,
"namerica": 2.7,
"asia": 2.2,
"lamerica": 0.5,
"meast": 0.4,
"africa": 0.3,
"latitude": 45.74
}, {
"year": "2023",
"europe": 2.8,
"namerica": 2.9,
"asia": 2.4,
"lamerica": 0.3,
"meast": 0.9,
"africa": 0.5,
"latitude": 39.74
}];
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
var xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root, {
categoryField: "year",
renderer: am5xy.AxisRendererX.new(root, {
cellStartLocation: 0.1,
cellEndLocation: 0.9
}),
tooltip: am5.Tooltip.new(root, {})
}));
var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
min: 0,
renderer: am5xy.AxisRendererY.new(root, {})
}));
var latitudeAxisRenderer = am5xy.AxisRendererY.new(root, {opposite:true});
var latitudeAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
syncWithAxis: yAxis, // Synchronize axes to get a more readable grid
renderer: latitudeAxisRenderer
}));
var latitudeSeries = chart.series.push(am5xy.LineSeries.new(root, {
xAxis: xAxis,
yAxis: latitudeAxis,
valueYField: "latitude",
categoryXField: "year", // Use categoryXField instead of valueXField
tooltip:am5.Tooltip.new(root, {
labelText:"latitude: {valueY}"
})
}));
latitudeSeries.strokes.template.setAll({ strokeWidth: 2 });
// Add circle bullet
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/#Bullets
latitudeSeries.bullets.push(function() {
var graphics = am5.Circle.new(root, {
strokeWidth: 2,
radius: 5,
stroke: latitudeSeries.get("stroke"),
fill: root.interfaceColors.get("background"),
});
graphics.adapters.add("radius", function(radius, target) {
return target.dataItem.dataContext.townSize;
})
return am5.Bullet.new(root, {
sprite: graphics
});
});
latitudeSeries.data.setAll(data);
// Add series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
function makeSeries(name, fieldName, stacked) {
var series = chart.series.push(am5xy.ColumnSeries.new(root, {
stacked: stacked,
name: name,
xAxis: xAxis,
yAxis: yAxis,
valueYField: fieldName,
categoryXField: "year"
}));
series.columns.template.setAll({
tooltipText: "{name}, {categoryX}:{valueY}",
width: am5.percent(90),
tooltipY: am5.percent(10),
// Set column and stroke transparency for more readability
opacity: 0.75,
stroke: "transparent"
});
xAxis.data.setAll(data);
series.data.setAll(data);
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
series.appear();
series.bullets.push(function () {
return am5.Bullet.new(root, {
locationY: 0.5,
sprite: am5.Label.new(root, {
text: "{valueY}",
fill: root.interfaceColors.get("alternativeText"),
centerY: am5.percent(50),
centerX: am5.percent(50),
populateText: true
})
});
});
legend.data.push(series);
}
makeSeries("Europe", "europe", true);
makeSeries("North America", "namerica", true);
makeSeries("Asia", "asia", true);
makeSeries("Latin America", "lamerica", true);
makeSeries("Middle East", "meast", true);
makeSeries("Africa", "africa", true);
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
chart.appear(1000, 100);
}); // end am5.ready()
</script>
<!-- HTML -->
<div id="chartdiv"></div>
Trying to use plotly.js so show student grade transitions between quizzes. In Plotly.js the node order (i.e. score bands such as 0-40) is changed between the quizzes. Is there a way to keep them in the same order between quizzes (eg 0.40 is always at the bottom).
Thanks
var trace1 = {
type: "sankey",
orientation: "h",
node: {
groups: ["Quiz 1", "Quiz 2", "Quiz 3", "Quiz 4"],
label: ["0-40", "41-60", "61-70", "71-80", "81-100","0-40", "41-60", "61-70", "71-80", "81-100","0-40", "41-60", "61-70", "71-80", "81-100"],
color: ["red", "orange", "blue", "green", "green","red", "orange", "blue", "green", "green","red", "orange", "blue", "green", "green"]
},
link: {
source: [0,1,2,3,4,5,6,7,8,9],
target: [6,6,7,8,8,11,11,12,14,14],
value: [3,1,1,2,1,3,1,1,2,4,5]
}
};
var data = [ trace1 ];
var layout = {
title: {
text:'SANKEY Title',
font: {
family: 'Courier New, monospace',
size: 24
},
},
annotations: [{
text: 'QUIZ 1',
x: 0.0,
y: 1.1,
showarrow: false,
font: {size: 12}
},
{
text: 'QUIZ 2',
x: 0.5,
y: 1.1,
showarrow: false,
font: {size: 12}
},
{
text: 'QUIZ 3',
x: 1.0,
y: 1.1,
showarrow: false,
font: {size: 12}
},
{
text: 'QUIZ 4',
x: 1.5,
y: 1.1,
showarrow: false,
font: {size: 12}
}],
width: 600,
};
Plotly.newPlot('myDiv', data, layout);
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="myDiv"></div>
You can define the node position as documented here.
node: {
x: [0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3, 0.3, 0.3],
y: [0.1, 0.2, 0.3, 0.4, 0.5, 0.1, 0.2, 0.3, 0.4, 0.5, 0.1, 0.2, 0.3, 0.4, 0.5],
pad: 50, // 50 Pixels
}
Keep your y values consistent per grade-band and you should be all set. Here's a CodePen example.
I try to create some object that a user could able by mouse rotate use Three.js and webgl. It's displaying fine when a screen has a full HD resolution (1960x1080) but when a user screen had resolution roughly 1366x768 object is ugly (blurred). Most notably text on the image.
Originally image has the resolution 1024x748 and the scene has a size roughly 530x270.
Clear - https://ibb.co/0s7W2hk
Blurred - https://ibb.co/tzCkq6W (in some cases blur corruption have more influence)
I connect the model to the scene by next code
// ...
scene.add({
genotype: VOLUMETRIC_OBJECT,
phenotype: MODELLED_MESH,
data: {
model: 'assets/FBX 2013/model.FBX',
position: {
x: 0,
y: isMobile ? 0.05 : 0.375,
z: 0,
},
scale: isMobile ? {
x: 70e-3,
y: 70e-3,
z: 70e-3,
} : {
x: 75e-3,
y: 75e-3,
z: 75e-3,
},
name: 'model',
material: {
hb_03_label1Model: {
map: 'assets/mm1.jpg',
alphaMap: 'assets/mam1.jpg',
color: 0xffffff,
specular: new Color(0xffffff),
shininess: 5,
transparent: true,
opacity: 1,
needsUpdate: true,
},
body_hb_03Model: {
normalMap: 'assets/mnm2.jpg',
color: 0xaaaaaa,
specular: new Color(0xFFFFFF),
opacity: 0.35,
shininess: 100,
transparent: true,
needsUpdate: true,
normalScale: {
x: 1,
y: 1,
},
},
hb_03_leqidoModel: {
type: MATERIAL__SHADER,
map: 'assets/mm3.jpg',
thicknessMap: 'assets/mtm3.jpg',
specularMap: 'assets/msm3.jpg',
normalMap: 'assets/mnm3.jpg',
repeat: [10, 10],
color: 0xffffff,
refractionRatio: 0.985,
reflectivity: 0.15,
diffuse: new Vector3(1, 0.3, 0.3),
thicknessColor: new Vector3(0.11, 0.11, 0.11),
needsUpdate: true,
uniformsNeedUpdate: true,
},
hb_03_cappaModel: {
color: 0x00AD16,
needsUpdate: true,
},
},
},
},
(model) => {
// ...
},
)
Update 1:
In my case when I change mag and min filters to Linear, I have strong sharpness and text not readable, again.
I think, for the best result, I need to use mag filter as Linear and min filter as LinearMipMapLinearFilter with the generated by myself mipmap.
But, currently, generate custom mipmap so strong for me. I did increase anisotropy for texture, and text is displayed acceptable
I would like to format the y axis to display percentages. If I don't change the y axis format it displays the values perfectly but if I add the y axis modifier lines the values appear at the y axis.
This is the code: https://jsfiddle.net/3pssrmjm/
and this is the y axis modifier code:
axis:{
y: {
tick:{
format: d3.format('%')
}
}
}
Small change. You had 2 separate axis objects, the second was overriding the first.
chart = c3.generate({
data: {
x: 'time',
xFormat: '%Y-%m-%d',
json: [{
"time": "2016-07-27",
"Fehérje": 0.69,
"Szénhidrát": 1.22,
"Na": 2.47,
"Ca": 0.32,
"Ka": 0.3,
"Zsír": 1.46,
"P": 0.66
}, {
"time": "2016-07-16",
"Fehérje": 0.06,
"Szénhidrát": 0.12,
"Na": 1,
"Ca": 0.05,
"Ka": 0.01,
"Zsír": 0.02,
"P": 0.13
}, {
"time": "2016-07-02",
"Fehérje": 0.44,
"Szénhidrát": 0.32,
"Na": 2.12,
"Ca": 0.47,
"Ka": 0.7,
"Zsír": 0.68,
"P": 0.39
}],
keys: {
x: 'time',
value: ['Szénhidrát', 'Zsír', 'Na', 'Ca', 'K', 'P']
}
},
axis: {
x: {
type: "timeseries",
tick: {
format: '%m-%d'
}
},
y: {
tick:{
format: d3.format('%')
}
}
},
line: {
connectNull: true
}
});
And a fiddle: https://jsfiddle.net/f47r3fxm/
Please guide me what i am doing wrong.I am using c3.js for showing chart in my webpage.Now i have requirement where i need to show spline and scatter chart together.I have searched in c3.js and came across combinational chart (http://c3js.org/samples/chart_combination.html). But when i used it for scatter and spline chart is not coming at all
Below is my code
<!-- Load c3.css -->
<link href="c3.css" rel="stylesheet" type="text/css">
<!-- Load d3.js and c3.js -->
<script src="d3.js" charset="utf-8"></script>
<script src="c3.js"></script>
<div class="chart" id="chart" ></div>
<script>
var chart = c3.generate({
data: {
xs: {
setosa: 'setosa_x',
},
// iris data from R
columns: [
["setosa", 3.0, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3.0, 3.0, 4.0, 4.4, 3.9, 3.5, 3.8, 3.8, 3.4, 3.7, 3.6, 3.3, 3.4, 3.0, 3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.6, 3.0, 3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3.0, 3.8, 3.2, 3.7, 3.3],
["setosa_x", 3.2, 3.2, 3.1, 2.3, 2.8, 2.8, 3.3, 2.4, 2.9, 2.7, 2.0, 3.0, 2.2, 2.9, 2.9, 3.1, 3.0, 2.7, 2.2, 2.5, 3.2, 2.8, 2.5, 2.8, 2.9, 3.0, 2.8, 3.0, 2.9, 2.6, 2.4, 2.4, 2.7, 2.7, 3.0, 3.4, 3.1, 2.3, 3.0, 2.5, 2.6, 3.0, 2.6, 2.3, 2.7, 3.0, 2.9, 2.9, 2.5, 2.8],
['data3', 300, 200, 160, 400, 250, 250],
],
type: 'scatter',
types: {
data3: 'spline',
},
},
axis: {
x: {
label: 'Sepal.Width',
tick: {
fit: false
}
},
y: {
label: 'Petal.Width'
}
}
});
</script>
Thanks
I have also wondered.
To plot the line chart on the same x axis as the scatter chart, you will need an x axis and set it to the same axis as scatter chart. The setosa_x data does not have to be in order, but it should be so you can make a useful line chart on the shared x axis. This affects how setosa can be defined also.
Because the x axis will have several numbers the same, you will need to giver your line data some nulls.
You need to give the scatter and line charts different axes{} to work from (y and y2). Also need to set limits with min and max for each.
You can cut and paste the data in the arrays into M Excel and order the chronoligically
var chart = c3.generate({
data: {
x:'setosa_x',
xs: {
setosa: 'setosa_x',
},
// iris data from R
columns: [
//['x',2.3,2.9,3.0,3.0,3.0,3.0,3.0,3.0,3.1,3.1,3.1,3.1,3.2,3.2,3.2,3.2,3.2,3.3,3.3,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.5,3.5,3.5,3.5,3.5,3.6,3.6,3.6,3.7,3.7,3.7,3.8,3.8,3.8,3.8,3.9,3.9,4.0,4.1,4.2,4.4],
['data3', 100, 200, 300, null, null, 200, null, 160, 400, 250, 250,100, 200, 300, 200, 160, 400, 250, 250,100, 200, 300, 200 ],
["setosa_x",2.3,2.9,3.0,3.0,3.0,3.0,3.0,3.0,3.1,3.1,3.1,3.1,3.2,3.2,3.2,3.2,3.2,3.3,3.3,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.5,3.5,3.5,3.5,3.5,3.6,3.6,3.6,3.7,3.7,3.7,3.8,3.8,3.8,3.8,3.9,3.9,4.0,4.1,4.2,4.4],
["setosa", 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.4, 0.4, 0.3, 0.3, 0.3, 0.2, 0.4, 0.2, 0.5, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.1, 0.2, 0.2, 0.2, 0.2, 0.1, 0.2, 0.2, 0.3, 0.3, 0.2, 0.6, 0.4, 0.3, 0.2, 0.2, 0.2, 0.2],
],
axes: {
// setosa_x: 'x',
setosa: 'y2',
data3: 'y'
},
type: 'scatter',
types: {
data3 : 'spline'
}
},
axis: {
y: {
min: 35,
show: true
},
y2: {
max: 0.5,
show: true
}
}
});
The above answer was a useful start for me but it's ultimately off point. The C3 system allows one to specify multiple chart types, without having to resort to creating multiple y axes, which should almost always be avoided because it's too easy to manipulate inferences in this manner (think of truncating one axis to increase the appearance of variability or vise versa).
Simply add in the x and y values respectively for each series you'd like to plot and refer to the type of chart that needs to be plotted in the types argument in the data object. See below:
var setosa_x = [2.3,2.9,3.0,3.0,3.0,3.0,3.0,3.0,3.1,3.1,3.1,3.1,3.2,3.2,3.2,3.2,3.2,3.3,3.3,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.5,3.5,3.5,3.5,3.5,3.6,3.6,3.6,3.7,3.7,3.7,3.8,3.8,3.8,3.8,3.9,3.9,4.0,4.1,4.2,4.4];
var setosa = [0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.4, 0.4, 0.3, 0.3, 0.3, 0.2, 0.4, 0.2, 0.5, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.1, 0.2, 0.2, 0.2, 0.2, 0.1, 0.2, 0.2, 0.3, 0.3, 0.2, 0.6, 0.4, 0.3, 0.2, 0.2, 0.2, 0.2];
var new_setosa = setosa.map(function(x){
return 0.75 * x + .25;
});
var new_setosa_x = setosa_x.map(function(x){
return x + .10;
})
var other_chart = c3.generate({
bindto: '#other_chart',
data: {
xs: {
setosa: 'setosa_x',
other: 'other_x'
},
// iris data from R
columns: [
["setosa_x"].concat(setosa_x),
["setosa"].concat(setosa),
["other_x"].concat(new_setosa_x),
["other"].concat(new_setosa)
],
types: {
setosa: 'scatter',
other : 'spline'
}
}
});