HighCharts之圖表背景設定

暖楓無敵發表於2016-05-10

 為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();


相關文章