i am using backbonejs framework for front-end and using chartjs for charts, so to keep it simple :
i have a view that renders tabs perfectly and in every tab there is a chart in it
first time chart loads perfectly and every thing went great
when i click on the some tab again it re-renders all it content including the chart from scratch
problem : "when switching back to tabs chart does not show"
my function is like :
createChart: function(collection){
var that = this;
/* this is for the collection that i coming from an API and i am just spliting it into two arrays */
var data1 = [],
data2 = [];
collection.each(function(model){
data1.push(model.get('count'));
data2.push(model.get('title'));
})
// chartjs code
var data = {
labels: data2,
datasets: [
{
label: "My Second dataset",
fillColor: "#007B9D",
strokeColor: "#00BFF3",
pointColor: "#00BFF3",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: data1
}
]};
//"this" is the reference to above declared variable
this.ctx = document.getElementById("user-activity- chart").getContext("2d");
this.myBarChart = new Chart(that.ctx).Bar(data);
console.log(this.ctx);
console.log(this.myBarChart);
},
i logged first time values into console and it is as following
ctx log : CanvasRenderingContext2D {textBaseline: "alphabetic", textAlign: "start", font: "12px "Helvetica Neue", Helvetica, Arial, sans-serif", lineDashOffset: 0, miterLimit: 10…}
myBarchart log: Chart.Type.extend.ChartType {options: Object, chart: Chart, id: "chart-0", ScaleClass: function, datasets: Array[1]…}
i logged second time(after switching tab) values into console and it is as following
ctx log: CanvasRenderingContext2D {textBaseline: "alphabetic", textAlign: "start", font: "12px "Helvetica Neue", Helvetica, Arial, sans-serif", lineDashOffset: 0, miterLimit: 10…}
myBarChart log: Chart.Type.extend.ChartType {options: Object, chart: Chart, id: "chart-1", ScaleClass: function, datasets: Array[1]…}
i have tried
myBarchart.destroy()
myBarchart.clear()
myBarchart.update()
all these methods
and also tried doing solution over here : https://gist.github.com/skhisma/5689383
please donot judge me as i am new here in backbonejs thanks in advance