HighCharts之图表背景设置

 为HighCharts设置XAxis的PlotBands属性,全部代码如下:

Highcharts chart = new Highcharts("HC" + divName)
               .InitChart(new Chart
               {
                   DefaultSeriesType = CT_type,
                   Width = _width,
                   Height = _height,
                   ClassName = _Title,
                   BackgroundColor = null
               }).SetCredits(new Credits { Enabled = false })
               .SetTitle(new Title
               {
                   Text = _Title
               })
               .SetXAxis(new XAxis
               {
                   Title = new XAxisTitle { Text = "单位:" + unitName },
                   Categories = xCategoryList.ToArray(),
                   Reversed = false,
                   Opposite = false,
                   PlotBands = new[]{
                     new  XAxisPlotBands{
                      Color=ColorTranslator.FromHtml("#FCFFC5"),
                      From=7,
                      To=12,
                      Label=new XAxisPlotBandsLabel {Text="上午工作时间"}
                     },
                    new XAxisPlotBands{
                      Color=ColorTranslator.FromHtml("#FCFFC5"),
                      From=13,
                      To=18,
                      Label=new XAxisPlotBandsLabel {Text="下午工作时间"}                    
                    }                   
                   }
               })
               .SetYAxis(new YAxis
               {
                   Title = new YAxisTitle { Text = "单位:" + SeriesUnit },
                   Min = 0,
                   PlotLines = new[]
                                          {
                                              new YAxisPlotLines
                                              {
                                                  Value = 0,
                                                  Width = 1,
                                                  Color = ColorTranslator.FromHtml("#808080")
                                              }        }
               })
               .SetTooltip(new Tooltip
               {
                   Formatter = ToolTip_info,
                   ValueDecimals = 2
               })
                .SetPlotOptions(new PlotOptions
                {
                    Column = new PlotOptionsColumn
                    {
                        BorderWidth = 2,
                        BorderColor = ColorTranslator.FromHtml("#edc240")
                    }
                })
               .SetLegend(new Legend
               {
                   Enabled = false
               })
               .SetSeries(new[]
                           {
                               new Series { Name ="", Data = new Data(yDataSeriesList.ToArray()),Color=ColorTranslator.FromHtml("#f5e2a7")}
                           }
                 );
                return chart.ToHtmlString();


你可能感兴趣的:(HighCharts之图表背景设置)