将图表放置到容器中

时间:2017-04-03 12:23:27

标签: javascript jquery html drag

我这里有一个AmCharts的例子,我已经制作了拖放功能,但我需要将图表放入容器并适合大小。有人知道吗?谢谢你的帮助

这里是小提琴:

http://jsfiddle.net/ngg2f5gz/1/

拖放功能

$( function() {
    $( "#chartdiv" ).draggable();
    $( "#container" ).droppable({
      drop: function( event, ui ) {
        $( this )
          .addClass( "ui-state-highlight" )
          .find( "p" )
            .html( "Dropped!" );
      }
    });
  } );

1 个答案:

答案 0 :(得分:1)

以下是:

$( "#container" ).droppable({
  drop: function( event, ui ) {
    # clear the container
    $(this).html('');

    # append chart to container
    ui.draggable.appendTo($(this));

    # modify some css to fit
    ui.draggable.css({
      width: '100%',
      height: '100%',
      top: 0,
      left: 0,
      position: 'absolute'
    });

    # destroy draggable after chart was dropped
    ui.draggable.draggable('destroy');
  }
});

并将position: relative;添加到#container的css规则中。