score:1
Accepted answer
I can only suggest clearing canvas by yourself. Like this
$(graphElement).find('canvas')[0].getContext('2d').clearRect(0, 0, canvasWidth, canvasHeight);
Full code (jsfiddle)
console.clear();
$(function(){
var canvasWidth = 650, canvasHeight = 150;
// create new cubism.js context to render
var graphContext = cubism.context()
.serverDelay(1000) // allow 1second delay
.step(1000) // 1 second steps
.size(canvasWidth); // 50px wide
// create a new metric
// this allows you to retrieve values from some source
// this is data-source agnostic, so this does not matter.
var graphMetric = graphContext.metric(function(start, stop, step, callback) {
var values = [];
start = +start;
stop = +stop;
while (start < stop) {
start += step;
values.push(Math.random());
}
callback(null, values);
});
// here we create a new element and then append it to our
// parent container. Then we call d3 to select the newly created
// div and then we can create a chart
var graphElement = document.createElement("div");
$("#insertElement").append(graphElement);
d3.select(graphElement).call(function(div) {
div.append("div")
.attr("class", "axis top")
.call(graphContext.axis().orient("top"));
div.append("div")
.attr("class", "rule")
.call(graphContext.rule());
div.selectAll(".horizon")
.data([graphMetric])
.enter().append("div")
.attr("class", "horizon")
.call(graphContext.horizon()
.height(canvasHeight)
);
});
$('#reset').on('click', function () {
$(graphElement).find('canvas')[0].getContext('2d').clearRect(0, 0, canvasWidth, canvasHeight);
});
});
Source: stackoverflow.com
Related Query
- Reset or Clear Cubism Graph
- Reset and clear function in D3.js
- add a drag behaviour on a cubism graph
- How to reset force directed graph to its original position?
- How to reset d3 graph to its original place?
- How to move D3 graph to initial zoom and at 0,0 position - RESET Graph?
- Unable to resize Cubism graph D3.js
- Reset Interval breaks my continuos flow of the graph
- Highlight selected node, its links, and its children in a D3 force directed graph
- producing a "live" graph with D3
- NVD3, Clear svg before loading new chart
- Adding FontAwesome icons to a D3 graph
- How to make force layout graph in D3.js responsive to screen/browser size
- 3 dimension (X, Y and Z) graph using D3.js
- Why does d3.js v3 break my force graph when implementing zooming when v2 doesn't?
- Updating links on a force directed graph from dynamic json data
- Add text label to d3 node in Force directed Graph and resize on hover
- Real time line graph with nvd3.js
- d3 update data and update graph
- Simple graph of nodes and links without using force layout
- How to convert/save d3.js graph to pdf/jpeg
- Zoomable, Google-Finance-style time series graph in D3 or Rickshaw?
- D3 force directed graph with drag and drop support to make selected node position fixed when dropped
- Zoomable network graph in AngularJS
- How to add a click event on nvd3.js graph
- Add text/label onto links in D3 force directed graph
- HTML5 canvas alternatives for d3.js, graph visualization library
- Is D3.js the right choice for real-time visualization of Neo4j Graph DB data
- Creating a border around your D3 graph
- Configure fixed-layout static graph in d3.js
More Query from same tag
- Render D3 Hierarchical Edge Bundling
- D3 remove comma delimiters for thousands
- Tick marks on both sides of axis on d3 scale
- Include custom library like D3js in ESlint configuration?
- nvd3 + lineplusbarchart + allign axises
- d3.selection type check in IE
- How to toggle data points on and off along with lines in multi-line chart
- Setting up Scale Domain and Bar Width for multiple bar charts in one page
- D3js how to append 2 children at the same level in .enter context
- How to add text at the end of Arc
- Strange behavior displaying a list from an array in d3.js
- d3 grouped bar chart highlight group on mouseover
- nvd3 space between bars
- dc.js reset does not affect mouseZoomable
- d3 topojson wont generate state outlines
- Convert R dataframe into tough JSON list of lists for d3.hierarchy model
- Process and send mouse event beneath the SVG element
- d3.js: How to deal with svg elements that are being appended on the same position, one on top of the other?
- How to pass Javascript dynamic array to d3 dimple chart
- Why does d3 date axis fail in Firefox for some particular date domains?
- python: how to save dynamically rendered html web page code
- D3 zoomable sunburst not fully circle
- Marker end position not working correctly d3js
- how to add text on line in D3?
- how to set d3.brush extent right?
- d3js stack chart: how to add text on each layer?
- D3.js Why do some rectangles have wider strokes than others (in a stacked bar chart)?
- Extending paths in D3 with transition
- Python equivalent of D3.js
- D3 ordinal scale adding numbers to the end