在ActionResult中改变HighCharts中的标题样式

时间:2016-03-22 14:34:10

标签: javascript asp.net-mvc highcharts

这是我的代码:

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中更改标题的样式,字体大小?

1 个答案:

答案 0 :(得分:2)

在你的SetTitle()函数中,你可以传递css,如字体,颜色等,如下所示:

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

让我知道它是否有帮助!