/// <summary> /// Sets the flot axis style. /// </summary> /// <param name="styleAxis">The style axis.</param> /// <param name="flotAxis">The flot axis.</param> private void SetFlotAxisStyle(AxisStyle styleAxis, AxisOptions flotAxis) { if (styleAxis != null) { flotAxis.color = styleAxis.Color; flotAxis.timeformat = styleAxis.DateTimeFormat; if (styleAxis.Font != null) { flotAxis.font.color = styleAxis.Font.Color; flotAxis.font.family = styleAxis.Font.Family; flotAxis.font.size = styleAxis.Font.Size; } } }
/// <summary> /// Sets the flot axis style. /// </summary> /// <param name="styleAxis">The style axis.</param> /// <param name="flotAxis">The flot axis.</param> private void SetFlotAxisStyle( AxisStyle styleAxis, AxisOptions flotAxis ) { if ( styleAxis != null ) { flotAxis.color = styleAxis.Color; flotAxis.timeformat = styleAxis.DateTimeFormat; if ( styleAxis.Font != null ) { flotAxis.font.color = styleAxis.Font.Color; flotAxis.font.family = styleAxis.Font.Family; flotAxis.font.size = styleAxis.Font.Size; } } }
/// <summary> /// Sets the chart style. /// </summary> /// <param name="chartStyle">The chart style.</param> public void SetChartStyle( ChartStyle chartStyle ) { if ( chartStyle.SeriesColors != null && chartStyle.SeriesColors.Count() > 0 ) { this.colors = chartStyle.SeriesColors.ToArray(); } if ( chartStyle.Grid != null ) { this.grid = this.grid ?? new GridOptions(); this.grid.backgroundColor = chartStyle.Grid.BackgroundColorGradient != null ? ToFlotColorGradient( chartStyle.Grid.BackgroundColorGradient ) : chartStyle.Grid.BackgroundColor; this.grid.color = chartStyle.Grid.ColorGradient != null ? ToFlotColorGradient( chartStyle.Grid.ColorGradient ) : chartStyle.Grid.Color; this.grid.borderWidth = chartStyle.Grid.BorderWidth; this.grid.borderColor = chartStyle.Grid.BorderColor; } this.xaxis = this.xaxis ?? new AxisOptions(); SetFlotAxisStyle( chartStyle.XAxis, this.xaxis ); this.yaxis = this.yaxis ?? new AxisOptions(); SetFlotAxisStyle( chartStyle.YAxis, this.yaxis ); this.yaxis.tickFormatter = @" function (val, axis) { // show commas // from http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); }".Trim(); SetFlotLinesPointsBarsStyle( chartStyle, this.series.lines ); SetFlotLinesPointsBarsStyle( chartStyle, this.series.bars ); SetFlotLinesPointsBarsStyle( chartStyle, this.series.points ); if ( chartStyle.Legend != null ) { this.legend = new Legend(); this.legend.show = chartStyle.Legend.Show ?? true; this.legend.labelBoxBorderColor = chartStyle.Legend.LabelBoxBorderColor; this.legend.noColumns = chartStyle.Legend.NoColumns; this.legend.position = chartStyle.Legend.Position; this.legend.backgroundColor = chartStyle.Legend.BackgroundColor; this.legend.backgroundOpacity = chartStyle.Legend.BackgroundOpacity; this.legend.container = chartStyle.Legend.Container; } this.customSettings = this.customSettings ?? new CustomSettings(); // copy Title styles to Flot custom settings if ( chartStyle.Title != null ) { if ( chartStyle.Title.Font != null ) { this.customSettings.titleFont = new ChartFont(); this.customSettings.titleFont.color = chartStyle.Title.Font.Color; this.customSettings.titleFont.family = chartStyle.Title.Font.Family; this.customSettings.titleFont.size = chartStyle.Title.Font.Size; } if ( chartStyle.Title.Align != null ) { this.customSettings.titleAlign = chartStyle.Title.Align; } } // copy SubTitle styles to Flot custom settings if ( chartStyle.Subtitle != null ) { if ( chartStyle.Subtitle.Font != null ) { this.customSettings.subtitleFont = new ChartFont(); this.customSettings.subtitleFont.color = chartStyle.Subtitle.Font.Color; this.customSettings.subtitleFont.family = chartStyle.Subtitle.Font.Family; this.customSettings.subtitleFont.size = chartStyle.Subtitle.Font.Size; } if ( chartStyle.Subtitle.Align != null ) { this.customSettings.subtitleAlign = chartStyle.Subtitle.Align; } } // copy Goal Series Color to Flot custom settings this.customSettings.goalSeriesColor = chartStyle.GoalSeriesColor; if ( chartStyle.PieLabels != null ) { this.series.pie = this.series.pie ?? new Pie(); this.series.pie.label = new PieLabel(); this.series.pie.label.background = new { color = chartStyle.PieLabels.BackgroundColor, opacity = chartStyle.PieLabels.BackgroundOpacity }; } }