score:0
Got this fiddle on google search.This might help. http://jsfiddle.net/woqsazau/2/
HTML :
<div class="container">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" id="bs-tabs">
<li><a href="#length" role="tab" data-toggle="tab">Length</a>
</li>
<li class="active"><a href="#height" role="tab" data-toggle="tab">Height</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane" id="length">
<div class="canvas-holder">
<canvas id="lengthChart" class="chart"></canvas>
</div>
</div>
<div class="tab-pane active" id="height">
<div class="canvas-holder">
<canvas id="heightChart" class="chart"></canvas>
</div>
</div>
</div>
</div>
JS :
function getJSON() {
var data = {
"Series": {
"height": [{
"Date": "2014-09-19",
"Value": 85
}, {
"Date": "2014-09-23",
"Value": 74
}]
}
};
console.log(data);
var series = {};
// This loop is looping across all the series.
// x will have all the series names (heights, lengths, etc.).
for (var x in data.Series) {
var dates = [];
var values = [];
// Loop across all the measurements for every serie.
for (var i = 0; i < data.Series[x].length; i++) {
var obj = data.Series[x][i];
// Assuming that all the different series (heights, lengths, etc.) have the same two Date, Value attributes.
dates.push(moment(obj.Date).format("MMMM Mo"));
values.push(obj.Value);
}
// Keep the list of dates and values by serie name.
series[x] = {
dates: dates,
values: values
};
}
console.log(series.height.dates);
console.log(series.height.values);
//---------
//valueArray.push(Value);
//dateArray.push(moment(date).format("MMMM Mo"));
var dataArray = {
labels: series.height.dates,
datasets: [{
label: "Height",
strokeColor: "rgb(26, 188, 156)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: series.height.values
}]
};
function chartFunc(dataArray) {
var ctx = document.getElementById("heightChart").getContext("2d");
var myLineChart = new Chart(ctx).Line(dataArray, {
scaleShowGridLines: true,
bezierCurve: true,
bezierCurveTension: 0.4,
datasetStroke: false,
fillColor: "rgba(0,0,0,0)",
datasetFill: false,
responsive: true,
showTooltips: true,
animation: false
});
} //chartFunc
chartFunc(dataArray);
} //getJSON
$(document).ready(function () {
getJSON();
$(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
console.log("tab changed");
});
});
score:0
I have found a rather easy and somewhat lazy option. You can set all your tabs to "tab-pane active" This way all your charts on the tabs show and render, then
setTimeout(yourFunction, 250);
function yourFunction()
{
$('.nav-tabs a[href="#anytabExceptdefault"]').tab('show')
$('.nav-tabs a[href="#backtoyourdefaultTab"]').tab('show')
score:1
To me the solution is dead simple. Using the latest commit, update the Chart.Arc function as follows:
Chart.Arc = Chart.Element.extend({
inRange: function (chartX, chartY) {
var pointRelativePosition = helpers.getAngleFromPoint(this, {
x: chartX,
y: chartY
});
//Check if within the range of the open/close angle
var betweenAngles = (pointRelativePosition.angle >= this.startAngle && pointRelativePosition.angle <= this.endAngle),
withinRadius = (pointRelativePosition.distance >= this.innerRadius && pointRelativePosition.distance <= this.outerRadius);
return (betweenAngles && withinRadius);
//Ensure within the outside of the arc centre, but inside arc outer
},
tooltipPosition: function () {
var centreAngle = this.startAngle + ((this.endAngle - this.startAngle) / 2),
rangeFromCentre = (this.outerRadius - this.innerRadius) / 2 + this.innerRadius;
return {
x: this.x + (Math.cos(centreAngle) * rangeFromCentre),
y: this.y + (Math.sin(centreAngle) * rangeFromCentre)
};
},
draw: function (animationPercent) {
var easingDecimal = animationPercent || 1;
var ctx = this.ctx;
var innerRadius = (this.innerRadius < 0) ? this.innerRadius * -1 : this.innerRadius;
var outerRadius = (this.outerRadius < 0) ? this.outerRadius * -1 : this.outerRadius;
ctx.beginPath();
ctx.arc(this.x, this.y, outerRadius, this.startAngle, this.endAngle);
ctx.arc(this.x, this.y, innerRadius, this.endAngle, this.startAngle, true);
ctx.closePath();
ctx.strokeStyle = this.strokeColor;
ctx.lineWidth = this.strokeWidth;
ctx.fillStyle = this.fillColor;
ctx.fill();
ctx.lineJoin = 'bevel';
if (this.showStroke) {
ctx.stroke();
}
}
});
The thing to take note of is the ternary operator on both inner and outer radius to prevent negative values. This worked like a charm on my project. Charts continued to be responsive and there was NO deleterious effects by converting the radii into natural numbers (ie: positive)
score:10
I have had this problem. If I remember correctly I solved it by calling the chart js render when the active tab is shown using shown.bs.tab
(http://getbootstrap.com/javascript/#tabs)
i.e.
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
e.target // newly activated tab
//call chart to render here
});
Hope that helps.
score:18
Since the origin of this problem is display none of tab-content in bootstrap I've solved this with a little css hack.
.tab-content>.tab-pane {
display: block;
height: 0;
overflow: hidden;
}
.tab-content>.tab-pane.active {
height: auto;
}
Source: stackoverflow.com
Related Query
- Bootstrap 3 tabs & Chart.js - charts not loading on tabs
- how to not repeat code while creating multiple charts in chart js
- ChartJS charts not generating within tabs
- charts js, doughnut chart not rendering tooptips correctly
- Chart.js Charts not loading until hard refresh [Laravel] [Laravel Charts]
- Firefox is not responding when loading 800+ data sets in Bar Chart with Charts.Js
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Pie Chart using chart.js not showing up but bar charts are?
- Mixed chart not showing both charts simultaneously chart.js
- Multiple charts not loading on the same page
- Why chart is not working with Bootstrap Modal?
- Chart.js dynamically-created charts do not obey chart options
- Chart Js Change Label orientation on x-Axis for Line Charts
- ReferenceError: Chart is not defined - chartjs
- Chart.js: bar chart first bar and last bar not displaying in full
- How to save Chart JS charts as image without black background using blobs and filesaver?
- Chart.js responsive option - Chart not filling container
- show label in tooltip but not in x axis for chartjs line chart
- chartjs + Angular6 is not showing charts or any error
- Bootstrap grid not working with canvas
- Chart.js v2 charts do not display inside angular 2 (but Chart.js v1 works perfectly)
- Html chart does not fit a small Android WebView
- Chart.js ng2-charts colors in pie chart not showing
- Chart.JS Mixed Chart - Bars Not Showing
- Bootstrap modal showing when clicking individual points in Linechart but not in individual bars in Barchart
- Chart looks only grey, does not show the color - Chartjs,discordjs
- Angular-chart.js - Make line chart does not curve
- Charts js not showing
- angular-chartjs line chart TypeError: t.merge is not a function
- Chart.JS full-width, responsive doughnut chart with Bootstrap
More Query from same tag
- Uncaught TypeError: Cannot create property '_meta' on string
- How to fix the number of gridlines in X-Axis as label are too condensed
- Live updating chart with data from database with Chart.js
- Vue.js Vue-chart.js linear gradient background fill
- Adding a label to a doughnut chart in Chart.js shows all values in each chart
- Trying to get total sum based on months on ApexCharts with Php
- Convert FirestoreCollection into an array?
- ChartJS canvas not displaying colors in edge browser
- Radarwidth beyond label chart.js
- Chart.js 2.x: labels displaying over eachother
- Control which lines have points?
- How to make bars different colours in Chart.js with csv data?
- donut chart tooltip under center text
- Statistics page - Load every stats <div> one by one
- Chart.js with Node.js
- assigning line chart data in chartjs
- How do I customize the chart.js tooltip? Two labels have the same data, which I want to show you with each data
- Char.js - How to show labels by default in pie chart
- Chartjs xaxis labels auto decrease disabled
- Pause chart.js horizontal scroll
- Declare data value dynamicaly to chart js
- Making the labels responsive in chart js
- Setting ChartJS plugin on vue-chartjs not working
- How to show a "total" sum label on the top of stacked bars
- ChartJS - why is there a visual difference when displaying the same dataset alone or with more datasets?
- ChartJS passing data dynamically, then passing data into variables
- How to set 2 y-axis title (and/or label) on chartjs?
- Annotation plugin not working with Chart.js 2.8.0
- ng2-charts doughnut chart with different data per series
- How to edit style of negative x grid lines on Chart.js?