2013-04-06 44 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文件。