javascript - How to resize chart in Plottable.js -


i using plottable.js draw chart on page. resize chart when window being resized.

i've tried set size via css (as svg width , height attribute) no success.

here attempt set via svg attribute:

$('#svgsample').attr('width', w); $('#svgsample').attr('height', h); 

here attempt set via css:

$('#svgsample').css({     'width': w + 'px',     'height': h + 'px' }); 

any idea?

thanks

i believe need call plot.redraw() after setting svg attributes

here's example:

window.onload = function() {      var data = [          { x: 1, y: 1 },          { x: 2, y: 1 },          { x: 3, y: 2 },          { x: 4, y: 3 },          { x: 5, y: 5 },          { x: 6, y: 8 }      ];      var xscale = new plottable.scales.linear();      var yscale = new plottable.scales.linear();        var plot = new plottable.plots.scatter()          .adddataset(new plottable.dataset(data))          .x(function(d) { return d.x; }, xscale)          .y(function(d) { return d.y; }, yscale);        plot.renderto("#chart");      $('#chart').attr('width', 500);      $('#chart').attr('height', 400);      plot.redraw();  }
</style> <link rel="stylesheet" type="text/css" href="https://rawgithub.com/palantir/plottable/develop/plottable.css"> <style type="text/css">  body { background-color: #aaa; }  svg { background-color: #fff; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>  <script src="https://rawgithub.com/palantir/plottable/develop/plottable.js"></script>  <svg id="chart" width="100" height="100"></svg>


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -