2017-06-06 98 views
0

我正在使用外部按鈕來導出圖表。當我進入註釋模式並執行導出時,圖表會通過註釋導出。但是當圖表重新加載時,註釋模式不會恢復。Amchart註釋。從註釋模式返回正常模式

有人可以讓我知道如何從註釋返回到正常模式。使用菜單評論家

menuReviver: function (item, li) { 
    if (item.format === "XLSX" || item.format === "JSON") { 
    li.style.display = "none"; 
    } 

    $(li).click(function() { 
    if (item.action == "draw") { 
     $("#chart_annotations").val(1); 
    } 
    if (item.action == "cancel") { 
     $("#chart_annotations").val(0); 
    } 

    }); 

    return li; 
} 

現在在導出圖表圖像使用$

if (chart.export.drawing.buffer.enabled === true) { 
       // Exporting the annotated chart with out " 
       //chart.export.capture" 
       chart.export.toPNG({}, function (data) { 
        chartimage.postImageData(data, chart_image_name) 
       }); 
      } else { 

       chart.export.capture({ 
        // action: "draw" 

       }, function() { 
        this.toPNG({ 

        }, function (data) { 
         images.push({ 
          "image": data, 
          "fit": [523.28, 769.89] 
         }); 
         pending--; 
         if (pending === 0) { 
          chart.export.toPNG({ 
           content: images 
          }, function (data) { 
           chartimage.postImageData(data, chart_image_name) 
          }); 
         } 
        }); 
       }); 
      } 

     } 
+0

看看這裏:https://www.amcharts.com/kbase/using-export-api-functions-dynamically-save-load-chart-annotations/ – martynasma

+0

謝謝 - Martynasma。但是這個鏈接並沒有說如何恢復到正常模式。我需要像chart.export.drawing.buffer.enabled = false。更具體地說,我需要手動觸發註釋取消選項。有任何想法嗎? – balu

+0

剛剛發佈了另一個示例:https://www.amcharts.com/kbase/toggling-export-annotation-mode/將發佈爲其他人看到的SO答案。 – martynasma

回答

0

請看以下解決方法..

首先捕獲了一組事件和取消註釋(「#chart_annotations」 ).val()值作爲 標誌是否導出帶註釋的圖表或普通圖表。請從下面的代碼...

if (window.fabric) { 
    if ($("#chart_annotations").val() == 1) { 
     chart.export.toPNG({}, function (data) { 
     chartimage.postImageData(data, chart_image_name) 
     }); 
    } else { 

     chart.export.capture({ 
     //action: "change" 

     }, function() { 
     this.toPNG({ 

     }, function (data) { 
      images.push({ 
      "image": data, 
      "fit": [523.28, 769.89] 
      }); 
      pending--; 
      if (pending === 0) { 
      chart.export.toPNG({ 
       content: images 
      }, function (data) { 
       //post the image data using ajax 
       chartimage.postImageData(data, chart_image_name) 
      }); 
      } 
     }); 
     }); 
    } 
1

從註釋模式退出,只需使用導出插件的內部API方法done()

chart["export"].drawing.handler.done(); 

BTW,export關鍵字被保留,並會導致一些錯誤瀏覽器。最好通過指定鍵訪問導出實例:chart["export"].toPNG()chart.export.toPNG()