结合在Highcharts(Vue)中的服务器端导出和客户端导出。

huangapple go评论103阅读模式
英文:

Combine server side exporting and client side exporting in Highcharts (Vue)

问题

以下是翻译好的内容:

`client-side-exporting-chart.vue`

<template>
  <div>
    <chart :options="chartOptions" ref="chart" />
  </div>
</template>
<script>
import Highcharts from "highcharts";
import { Chart } from "highcharts-vue";
import offlineExporting from "highcharts/modules/offline-exporting";

offlineExporting(Highcharts);

export default {
  // ...
  components:{
    Chart
  },
  data(){
    return {
       chartOptions: {
         // ...
         exporting:{
           // ...
           fallbackToExportServer:false
         }
       }
     }
   }
 }
</script>
`export-server-chart.vue`

<template>
  <div>
    <chart :options="chartOptions" ref="chart" />
  </div>
</template>
<script>
import Highcharts from "highcharts";
import { Chart } from "highcharts-vue";
import exportingInit from "highcharts/modules/exporting";

exportingInit(Highcharts);

export default {
  // ...
  components:{
    Chart
  },
  data(){
    return {
       chartOptions: {
         // ...
         exporting:{
           // ...
           fallbackToExportServer:true
         }
       }
     }
   }
 }
</script>

请注意,代码部分没有进行翻译。

英文:

I was using Highcharts' export server to download charts as an image. I need to use the client-side(offline) exporting feature in a single chart due to the count of data points in the chart. After I use client-side exporting in just one chart, all of the charts turn into client-side exporting. How can I use both client-side exporting and Highcharts' export server in the same project?

Here is the relevant parts from the source code:

client-side-exporting-chart.vue

&lt;template&gt;
  &lt;div&gt;
    &lt;chart :options=&quot;chartOptions&quot; ref=&quot;chart&quot; /&gt;
  &lt;/div&gt;
&lt;/template&gt;
&lt;script&gt;
import Highcharts from &quot;highcharts&quot;;
import { Chart } from &quot;highcharts-vue&quot;;
import offlineExporting from &quot;highcharts/modules/offline-exporting&quot;;

offlineExporting(Highcharts);

export default {
  // ...
  components:{
    Chart
  },
  data(){
    return {
       chartOptions: {
         // ...
         exporting:{
           // ...
           fallbackToExportServer:false
         }
       }
     }
   }
 }
&lt;/script&gt;

export-server-chart.vue

&lt;template&gt;
  &lt;div&gt;
    &lt;chart :options=&quot;chartOptions&quot; ref=&quot;chart&quot; /&gt;
  &lt;/div&gt;
&lt;/template&gt;
&lt;script&gt;
import Highcharts from &quot;highcharts&quot;;
import { Chart } from &quot;highcharts-vue&quot;;
import exportingInit from &quot;highcharts/modules/exporting&quot;;

exportingInit(Highcharts);

export default {
  // ...
  components:{
    Chart
  },
  data(){
    return {
       chartOptions: {
         // ...
         exporting:{
           // ...
           fallbackToExportServer:true
         }
       }
     }
   }
 }
&lt;/script&gt;

答案1

得分: 1

模块在全局初始化,由于您的项目中只有一个Highcharts实例,每个组件都会自动启用离线导出。

在底层,该模块重新定义了menuItemDefinitions,并使用exportChartLocal方法代替exportChart方法。您可以通过添加以下配置来简单地恢复个别图表的行为:

exporting: {
  menuItemDefinitions: {
    downloadPNG: {
      textKey: 'downloadPNG',
      onclick: function() {
        this.exportChart();
      }
    },
    downloadJPEG: {
      textKey: 'downloadJPEG',
      onclick: function() {
        this.exportChart({
          type: 'image/jpeg'
        });
      }
    },
    downloadPDF: {
      textKey: 'downloadPDF',
      onclick: function() {
        this.exportChart({
          type: 'application/pdf'
        });
      }
    },
    downloadSVG: {
      textKey: 'downloadSVG',
      onclick: function() {
        this.exportChart({
          type: 'image/svg+xml'
        });
      }
    }
  }
}

在线演示: http://jsfiddle.net/BlackLabel/bgk5ftaj/

API 参考: https://api.highcharts.com/highcharts/exporting.menuItemDefinitions

英文:

Modules are initialized globally and since you have only one Highcharts instance in your project, offline-exporting is auto-enabled for each component.

Under the hood, the module redefines menuItemDefinitions and uses exportChartLocal instead of exportChart method. You can simply reverse back this behaviour for individual charts, by adding the below configuration:

  exporting: {
    menuItemDefinitions: {
      downloadPNG: {
        textKey: &#39;downloadPNG&#39;,
        onclick: function() {
          this.exportChart();
        }
      },
      downloadJPEG: {
        textKey: &#39;downloadJPEG&#39;,
        onclick: function() {
          this.exportChart({
            type: &#39;image/jpeg&#39;
          });
        }
      },
      downloadPDF: {
        textKey: &#39;downloadPDF&#39;,
        onclick: function() {
          this.exportChart({
            type: &#39;application/pdf&#39;
          });
        }
      },
      downloadSVG: {
        textKey: &#39;downloadSVG&#39;,
        onclick: function() {
          this.exportChart({
            type: &#39;image/svg+xml&#39;
          });
        }
      }
    }
  }

Live demo: http://jsfiddle.net/BlackLabel/bgk5ftaj/

API Reference: https://api.highcharts.com/highcharts/exporting.menuItemDefinitions

huangapple
  • 本文由 发表于 2023年6月19日 17:31:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定