如何在amCharts中将图表导出为图像时显示加载程序?

时间:2017-01-31 04:16:18

标签: javascript jquery charts amcharts

有时单击导出按钮会花费太多时间。单击多次会弹出一个弹出窗口,要求允许多个文件下载。当我不允许多次下载时,我无法下载任何图表。是否可以在后台进行一些下载时显示加载程序?还是有其他解决方案吗?

提前谢谢你。

2 个答案:

答案 0 :(得分:1)

您可以使用导出插件的{{3}}事件处理程序暂时禁用导出菜单,以便无法单击两次。

要做到这一点,只需使用一个空菜单项crateMenu()调用。

"export": {
  "enabled": true,
  "beforeCapture": function() {
    this.createMenu( [{
      "class": "export-main disabled"
    }] );
  }
}

请注意该项目的class设置。 “export-main”部分将确保该按钮看起来像默认导出按钮。我还添加了“禁用”部分。我们可以使用它来使用自定义CSS覆盖此类禁用元素的默认样式。即:

.amcharts-export-menu .export-main.disabled > a {
  cursor: default;
  opacity: 0.2;
}

我在这里提供了一个非常简单的CSS覆盖。您可以用更复杂的样式替换它,比如它中的GIF动画或其他东西。由你决定。

我们不需要重置菜单,因为导出插件会在导出完成时为我们执行此操作。

这是一个完整的工作演示:

var chart = AmCharts.makeChart("chartdiv", {
  "type": "serial",
  "theme": "light",
  "marginRight": 70,
  "dataProvider": [{
    "country": "USA",
    "visits": 3025,
    "color": "#FF0F00"
  }, {
    "country": "China",
    "visits": 1882,
    "color": "#FF6600"
  }, {
    "country": "Japan",
    "visits": 1809,
    "color": "#FF9E01"
  }, {
    "country": "Germany",
    "visits": 1322,
    "color": "#FCD202"
  }, {
    "country": "UK",
    "visits": 1122,
    "color": "#F8FF01"
  }, {
    "country": "France",
    "visits": 1114,
    "color": "#B0DE09"
  }, {
    "country": "India",
    "visits": 984,
    "color": "#04D215"
  }, {
    "country": "Spain",
    "visits": 711,
    "color": "#0D8ECF"
  }, {
    "country": "Netherlands",
    "visits": 665,
    "color": "#0D52D1"
  }, {
    "country": "Russia",
    "visits": 580,
    "color": "#2A0CD0"
  }, {
    "country": "South Korea",
    "visits": 443,
    "color": "#8A0CCF"
  }, {
    "country": "Canada",
    "visits": 441,
    "color": "#CD0D74"
  }],
  "valueAxes": [{
    "axisAlpha": 0,
    "position": "left",
    "title": "Visitors from country"
  }],
  "startDuration": 1,
  "graphs": [{
    "balloonText": "<b>[[category]]: [[value]]</b>",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "lineAlpha": 0.2,
    "type": "column",
    "valueField": "visits"
  }],
  "chartCursor": {
    "categoryBalloonEnabled": false,
    "cursorAlpha": 0,
    "zoomable": false
  },
  "categoryField": "country",
  "categoryAxis": {
    "gridPosition": "start",
    "labelRotation": 45
  },
  "export": {
    "enabled": true,
    "beforeCapture": function() {
      this.createMenu( [{
        "class": "export-main disabled"
      }] );
    }
  }

});
#chartdiv {
  width: 100%;
  height: 200px;
}

.amcharts-export-menu .export-main.disabled > a {
  cursor: default;
  opacity: 0.2;
}
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>

答案 1 :(得分:-1)

有J查询插件'fileDownload'。这是他们工作演示的链接。

http://jqueryfiledownload.apphb.com/