我使用下面的C#代码来生成一个图表,然后将其合并到HTML屏幕中。我想同时保存图表,最好是以svg格式保存到磁盘,以便以后合并到pdf文件中。所有的例子似乎都发生在JavaScript中。请问如何在C#代码中实现?
@using Highsoft.Web.Mvc.Charts
@using Highsoft.Web.Mvc.Charts.Rendering
@using System.Collections
@{
List<string> values = new List<string>();
Model.columnSeries.ForEach(u => values.Add(u.Name.ToString()));
var chartOptions = new Highcharts
{
Boost =
{
UseGPUTranslations = true
},
Title = new Title
{
Text = @Model.Title
},
Subtitle = new Subtitle
{
Text = @Model.SubTitle
},
XAxis = new List<XAxis>
{
new XAxis
{
Categories = values,
AllowDecimals = false,
Labels = new XAxisLabels
{
Rotation = -45
//Formatter = "formatXAxis"
}
}
},
YAxis = new List<YAxis>
{ new YAxis
{
Title = new YAxisTitle
{
Text = @Model.YaxisLabel
},
Labels = new YAxisLabels
{
//Formatter = "formatYAxis"
}
}
},
Tooltip = new Tooltip
{
PointFormat = "{series.name}: <b>{point.y:.0f}</b>"
},
PlotOptions = new PlotOptions
{
Column = new PlotOptionsColumn
{
}
},
Series = new List<Series>
{
new ColumnSeries
{
Data = @Model.columnSeries
}
}
};
chartOptions.ID = "Services";
var renderer = new HighchartsRenderer(chartOptions);
//chart.exportChart();
}
@Html.Raw(renderer.RenderHtml())
并插入到HTML(视图)中,
@await Component.InvokeAsync("ServiceChart", new {clientId = Model.ClientId, startDate = Model.StartDate, endDate = Model.EndDate})
1条答案
按热度按时间q35jwt9p1#
从网站下载SVG的示例如下:https://dotnet.highcharts.com/Highcharts/Demo/Gallery?demo=LineBasic&theme=default
然而,如果你想在后端做这件事,使用.NET Package 器它没有这样的功能。在这种情况下,您可以使用导出服务器:https://www.highcharts.com/docs/export-module/render-charts-serverside