2013-04-06 51 views

回答

1

只要將其導出爲圖片(PNG或JPG),並且圖像添加到一個PowerPoint幻燈片?大多數圖表在圖表右上角有一個下載(導出)按鈕。

+0

好的,我還想過這個想法,但有沒有辦法直接下載這個圖像在一個文件夾中bc例如瀏覽器詢問我是否想下載或沒有等......但我想要做的就是下載這個圖像在一個文件夾中沒有任何消息等,並從phppowerpoint讀取它們。 – 2013-04-06 17:13:51

+0

@GoodD似乎是你真正想要的是生成一個highcharts圖像服務器端並將其導入phppowerpoint。見http://www.highcharts.com/component/content/article/2-news/52-serverside-generated-charts關於如何做到這一點。 – 2013-04-06 23:42:34

0

我知道這是舊的,但我目前正試圖實現同樣的事情。 如果你樂於使用PNG或JPG格式,那麼我會用phantonJS(OpenQA.Selenium.PhantomJS)去提取SVG,然後任意轉換機制轉換成PNG/JPG

public IList<string> ExtractSVGs(string htmlFilePath) 
    { 
     IList<string> SVGs = new List<string>(); 
     foreach (string chart in getChartIds(htmlFilePath)) 
     { 
      SVGs.Add(ExtractSVG(htmlFilePath, chart)); 
     } 
     return SVGs; 
    } 

    private IList<string> getChartIds(string htmlFilePath) 
    { 
     IList<string> chartIds = new List<string>(); 
     string whatToFind = @" ""renderTo"": """; 
     foreach (string line in (System.IO.File.ReadLines(htmlFilePath))) 
     { 
      if (line.StartsWith(whatToFind)) 
       chartIds.Add("chart" + line.Substring(line.IndexOf(whatToFind) + whatToFind.Length, 32)); 
     } 
     return chartIds; 
    } 

    private string ExtractSVG(string htmlFilePath, string chartId) 
    { 
     var driverService = PhantomJSDriverService.CreateDefaultService(); 
     driverService.HideCommandPromptWindow = true; 
     driverService.LoadImages = true; 
     driverService.ProxyType = "none"; 
     driverService.LocalToRemoteUrlAccess = true; 
     driverService.WebSecurity = false; // may not be necessary 

     using (var driver = new PhantomJSDriver(driverService)) 
     { 
      driver.Navigate().GoToUrl(new Uri("file:///" + htmlFilePath)); 
      string svg = (string)driver.ExecuteScript(String.Format("return {0}.getSVG();", chartId), null); 
      driver.Close(); 
      return svg; 
     } 
    } 

你可以改變JS直接導出到PNG,但這需要鏈接到導出服務器(或使該代碼也在本地運行)。

在旁註中,您可能需要更改要查找的內容,具體取決於您如何構建html文件。