【问题标题】:Server-side rendering with Highcharts in C#在 C# 中使用 Highcharts 进行服务器端渲染
【发布时间】:2019-03-20 11:20:08
【问题描述】:

我想在基于 Web API 的 Angularjs (ASP.NET MVC 5) 应用程序的 Doc 报告上添加 highchart。与图表相关的一切都需要在 C# 上完成。我使用了http://export.highcharts.com/。我已经尝试了这个C# Server Side rendering建议教程的可能解决方案,但最终图像无效。我的代码如下。

string outputFile = System.Web.HttpContext.Current.Server.MapPath("image.jpg");
var settings = new HighchartsSetting
{
  ExportImageType = "jpg",
  ImageWidth = 800,
  ServerAddress = "http://export.highcharts.com/"
};

var client = new HighchartsClient(settings);
var options = new
{
  xAxis = new
  {
    categories = new[] { "Jan", "Feb", "Mar" }
  },
  series = new[]
  {
    new { data = new[] {29.9, 71.5, 106.4} }
  }
};

var res = await client.GetChartImageFromOptionsAsync(JsonConvert.SerializeObject(options));
System.IO.File.WriteAllBytes(outputFile, res);

还有其他方法或解决方案吗?

【问题讨论】:

  • 如果响应已经是图片,直接写入目标文件即可。
  • 响应返回字节,写入文件后图像显示无效。
  • 无效怎么办?你要求什么格式?您的 options 对象显示类别和数据,但不是所需的格式,即 svg、png、jpg
  • 我请求 jpg、png 但两者都无效。我也试过设置 var settings = new HighchartsSetting { ExportImageType = "jpg", ImageWidth = 1500, ServerAddress = "export.highcharts.com" }; var client = new HighchartsClient(settings)
  • 编辑问题,添加所有相关代码和您使用的库的链接。不要强迫人们猜测。也许你使用highcharts-export-client,也许不是。没有人会使用无效的服务器证书访问教程的链接

标签: c# asp.net-mvc highcharts


【解决方案1】:

最后,我能够在 C# 中呈现图表。单击 [此处] (https://drive.google.com/file/d/14tapUWIDCotxUJ1xtGmpWRp0H25pgI1i/view) 获取解决方案。使用“ProcessHighChartImageFromExportServer”方法在 Highchart server 上处理图表。我使用的是 Highchart 服务器而不是本地服务器,因为我们无法在 Azure 上运行 Phantom.exe。

【讨论】:

  • 我不想使用 Highcharts 导出服务器。我想使用您在此处创建的内部服务器:new HighChartsRenderServer(10000, 4, "127.0.0.1", "3003", true, null)。它可以工作,但图像不正确。
  • 我想我现在了解 HighChartsRenderServer 服务。它在内部运行 Phantom,在 Azure 上运行并不安全,对吗?
  • @Mark 是的,本地服务器使用幻像,但 azure web 不支持它。阅读here
  • 但是如果你使用虚拟机或其他任何你可以使用本地服务器。
  • 但正如我之前所说,您的解决方案在此处使用时无法生成正确的图像 GetFromInternalServer(highchartDat);
猜你喜欢
  • 2017-04-04
  • 2018-03-06
  • 2019-02-12
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-06
  • 2016-04-06
相关资源
最近更新 更多