更改ActionResult中HighCharts中的标题样式

Change Style of Title in HighCharts in ActionResult

本文关键字:标题 样式 HighCharts ActionResult 更改      更新时间:2023-09-26

这是我的代码:

public ActionResult SeriesWinsChart()
    {
        Highcharts chart = new Highcharts("chart")
            .InitChart(new Chart { PlotShadow = false })
            .SetTitle(new Title { Text = "Series Wins" })
            .SetCredits(new Credits { Enabled = false })
            //.SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.y; }" })
            .SetPlotOptions(new PlotOptions
            {
                Pie = new PlotOptionsPie
                {
                    AllowPointSelect = true,
                    Cursor = Cursors.Pointer,
                    DataLabels = new PlotOptionsPieDataLabels
                    {
                        Color = ColorTranslator.FromHtml("#000000"),
                        ConnectorColor = ColorTranslator.FromHtml("#000000"),
                        Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.y; }"
                    }
                }
            })
            .SetSeries(new Series
            {
                Type = ChartTypes.Pie,
                Name = "Series Wins",
                Data = new Data(new object[]
                {
                    new object[] { "Test1", db.Teams.Where(x => x.TeamName == "Team1").Sum(x => x.SeriesWins)},
                    new object[] { "Test2", db.Teams.Where(x => x.TeamName == "Team2").Sum(x => x.SeriesWins)}
                })
            });
        return View(chart);
    }

这是在局部视图中进行渲染。。所以我的代码只是:

@model DotNet.Highcharts.Highcharts

@(Model)

我已经对此主题进行了研究,但它涉及JS,我知道这就是HighCharts的来源,但我能在ActionResult中更改标题的样式和字体大小吗?

在您的SetTitle()函数中,您可以按如下方式传递css,如字体、颜色等:

.SetTitle(new Title { Text = "Series Wins", Style = "font: 'normal 14px Verdana, sans-serif',color : 'red'" })

如果有帮助,请告诉我!