private static string GetColorHexValueFromGenerator(ColourGenerator colourGenerator) { string colorHexValue; colorHexValue = "#" + colourGenerator.NextColour(); if (colorHexValue == "#FFFFFF" || colorHexValue == "#FFFF00") { colorHexValue = "#" + colourGenerator.NextColour(); } return(colorHexValue); }
static void Main(string[] args) { ColourGenerator generator = new ColourGenerator(); for (int i = 0; i < 896; i++) { Console.WriteLine(string.Format("{0}: {1}", i, generator.NextColour())); } }
public static Color GetRandomColour() { var r = new Random(); int rInt = r.Next(0, 896); // the largest amount of colours this class will generate var colorGen = new ColourGenerator(); string randomColourStr = "FFFFFF"; for (int i = 0; i < rInt; i++) { randomColourStr = colorGen.NextColour(); } return(HexStringToColor(randomColourStr)); }
private void FillInColorList() { SmoothColorGenerator Temp = new SmoothColorGenerator(); SmoothColorList = Temp.ColorList; ColourGenerator generator = new ColourGenerator(); UniqueColorList.Add(Color.FromRgb(0, 0, 0)); UniqueColorList.Add(Color.FromRgb(255, 255, 255)); for (int i = 0; i <= 895; i++) { Color c = new Color(); c = (Color)ColorConverter.ConvertFromString("#" + generator.NextColour()); UniqueColorList.Add(c); } }
public MapWindow() { InitializeComponent(); var generator = new ColourGenerator(); foreach (Center center in App.AppMap.Centers.Values) { string colour = "#" + generator.NextColour(); //var brush = new SolidColorBrush(Color.FromArgb(255, (byte) R, (byte) G, (byte) B)); //Color.FromRgb(Convert.ToByte(colour.Substring(1, 2), 16),Convert.ToByte(colour.Substring(3, 2), 16),Convert.ToByte(colour.Substring(5, 2), 16)); var brush = (SolidColorBrush)(new BrushConverter().ConvertFrom(colour)); var polygonPoints = new PointCollection(); center.OrderCorners(); //foreach (var border in center.Borders) //{ // polygonPoints.Add(new Point(border.Point.X * 3840, border.Point.Y * 2176)); //} foreach (var corner in center.Corners) { polygonPoints.Add(new Point(corner.Point.X*3840, corner.Point.Y*2176)); } var poly = new Polygon() { Points = polygonPoints, //Stroke = brush, //StrokeThickness = 1, Fill = brush }; canvas1.Children.Add(poly); canvas1.InvalidateVisual(); canvas1.UpdateLayout(); } }
public MapWindow() { InitializeComponent(); var generator = new ColourGenerator(); foreach (Center center in App.AppMap.Centers.Values) { string colour = "#" + generator.NextColour(); //var brush = new SolidColorBrush(Color.FromArgb(255, (byte) R, (byte) G, (byte) B)); //Color.FromRgb(Convert.ToByte(colour.Substring(1, 2), 16),Convert.ToByte(colour.Substring(3, 2), 16),Convert.ToByte(colour.Substring(5, 2), 16)); var brush = (SolidColorBrush)(new BrushConverter().ConvertFrom(colour)); var polygonPoints = new PointCollection(); center.OrderCorners(); //foreach (var border in center.Borders) //{ // polygonPoints.Add(new Point(border.Point.X * 3840, border.Point.Y * 2176)); //} foreach (var corner in center.Corners) { polygonPoints.Add(new Point(corner.Point.X * 3840, corner.Point.Y * 2176)); } var poly = new Polygon() { Points = polygonPoints, //Stroke = brush, //StrokeThickness = 1, Fill = brush }; canvas1.Children.Add(poly); canvas1.InvalidateVisual(); canvas1.UpdateLayout(); } }
public BasicChart() { InitializeComponent(); ColourGenerator generator = new ColourGenerator(); for (int i = 0; i < 20; i++) { DistinctColorList.Add(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#" + generator.NextColour()))); } }
public string GetRandomColorAsString() { var colorGenerator = new ColourGenerator(); return(colorGenerator.NextColour()); }
protected override void OnAppearing() { base.OnAppearing(); StackLayout graph = new StackLayout(); graph.Orientation = StackOrientation.Vertical; graph.HorizontalOptions = LayoutOptions.FillAndExpand; ColourGenerator generator = new ColourGenerator(); decimal total = 0.0M; foreach (var currencyAmount in AccountWallet) { total += currencyAmount.Amount; } foreach (var currencyAmount in AccountWallet) { var grid = new Grid(); var row = new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }; grid.RowDefinitions.Add(row); var labelColumn = new ColumnDefinition { Width = GridLength.Auto }; var barColumn = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }; grid.ColumnDefinitions.Add(labelColumn); grid.ColumnDefinitions.Add(barColumn); Label label = new Label(); label.Text = currencyAmount.Currency; grid.Children.Add(label, 1, 0); StackLayout boxViewWrapper = new StackLayout(); boxViewWrapper.Orientation = StackOrientation.Horizontal; boxViewWrapper.HorizontalOptions = LayoutOptions.FillAndExpand; boxViewWrapper.VerticalOptions = LayoutOptions.Center; RelativeLayout relativeLayout = new RelativeLayout(); BoxView bv = new BoxView(); bv.VerticalOptions = LayoutOptions.StartAndExpand; bv.BackgroundColor = Color.FromHex(generator.NextColour()); relativeLayout.Children.Add(bv, Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(parent.Width * (double)(currencyAmount.Amount / total)); }), Constraint.RelativeToParent((parent) => { return(parent.Height); })); boxViewWrapper.Children.Add(relativeLayout); grid.Children.Add(boxViewWrapper, 1, 1); graph.Children.Add(grid); } Content = graph; }
private void FillData() { BLL.Cls_PublicOperations.Dt = Bll_Chart.GetSpecialChartParameterData(this.Tag.ToString()); MainChart.Series.Clear(); MainChart.ChartAreas.Clear(); MainChart.Legends.Clear(); MainChart.Titles.Clear(); DataTable DtTrend = new DataTable(); System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); string TSql = BLL.Cls_PublicOperations.Dt.DefaultView[0]["TSQL"].ToString(); TSql = TSql.Replace("01/01/2015 00:00:00", StartDate.ToString("MM/dd/yyyy")); TSql = TSql.Replace("01/01/2016 00:00:00", EndDate.ToString("MM/dd/yyyy")); if (IsSHift3) { TSql = TSql.Replace("'12/12/2005'", "'" + Shift3beginDate.ToString("MM/dd/yyyy") + "'"); TSql = TSql.Replace("'12/13/2005'", "'" + Shift3Enddate.ToString("MM/dd/yyyy") + "'"); TSql = TSql.Replace("01:00:00", Shift3beginTime); TSql = TSql.Replace("06:00:00", Shift3EndTime); if (IsSHift3 && Times.Length < 5) { TSql = TSql.Replace("strtime", "AND (CAST(dbo.Tb_Client.StartTime AS time) BETWEEN '00:00:00' AND '00:00:00' "); } } TSql = TSql.Replace(" 60 ", " 1 "); TSql = TSql.Replace(" 3600 ", " 1 "); TSql = TSql.Replace("strtime", Times); if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["chartAxisXType"].ToString() == "1") { if (Mnu_FullDate.Checked) { TSql = TSql.Replace("strcolumns", ",StartDate "); } if (Mnu_Month.Checked) { TSql = TSql.Replace("strcolumns", ",CalIraniMonthID "); } if (Mnu_Week.Checked) { TSql = TSql.Replace("strcolumns", ",CalIraniWeekNum "); } if (Mnu_Year.Checked) { TSql = TSql.Replace("strcolumns", ",CalIraniYearID "); } if (Mnu_FullDate.Checked) { TSql = TSql + " order by startdate"; } if (Mnu_Month.Checked) { TSql = TSql + " order by CalIraniMonthID"; } if (Mnu_Week.Checked) { TSql = TSql + " order by CalIraniWeekNum"; } if (Mnu_Year.Checked) { TSql = TSql + " order by CalIraniYearID"; } } TSql = TSql.Replace("strcolumns", ""); DataTable TempTable = new DataTable(); TempTable = Bll_Public.GetDataTableFromTSQL(TSql); // TempTable.DefaultView.RowFilter = "Fullname <> '0'"; if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ShowChartPurpose"].ToString() == "True") { Dt = TempTable.DefaultView.Table.Select("Fullname <> '0'").CopyToDataTable(); DtTrend = TempTable.DefaultView.Table.Select("Fullname ='0'").CopyToDataTable(); } else { Dt = TempTable.DefaultView.Table.Select("Fullname <> '0'").CopyToDataTable(); } // Dt = Bll_Public.GetDataTableFromTSQL(TSql); MainChart.DataSource = Dt; MainChart.DataBind(); MainChart.Legends.Add("Default"); Boolean IsRandomColor = false; if (Dt.Rows.Count > 1) { if (Dt.DefaultView[0]["StateColor"].ToString() == Dt.DefaultView[1]["StateColor"].ToString() && Dt.DefaultView[0]["ProductLineDesc"].ToString() != Dt.DefaultView[1]["ProductLineDesc"].ToString()) { IsRandomColor = true; } } ColourGenerator generator = new ColourGenerator(); string LegendField, Xfield, YField, LabelType; YField = "Duration"; Xfield = ""; LegendField = ""; LabelType = ""; try { if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["chartAxisXType"].ToString() == "1") { if (Mnu_FullDate.Checked) { // MainChart.DataBindCrossTab(myReader, "Name", "Year", "Sales", "Label=Commissions"); /// MainChart.Series[Dt.DefaultView[i]["Fullname"].ToString()].Points.DataBindXY( Dt.DefaultView[i]["StartDate"].ToString(), ""); Xfield = "StartDate"; } if (Mnu_Month.Checked) { Xfield = "CalIraniMonthID"; } if (Mnu_Week.Checked) { Xfield = "CalIraniWeekNum"; } if (Mnu_Year.Checked) { Xfield = "CalIraniYearID"; } } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["chartAxisXType"].ToString() == "2") { Xfield = "StateCaption"; } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["chartAxisXType"].ToString() == "3") { Xfield = "Fullname"; } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["chartAxisXType"].ToString() == "7") { Xfield = "ProductLineDesc"; } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartLegentType"].ToString() == "1") { LegendField = "StateCaption"; } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartLegentType"].ToString() == "2") { LegendField = "Fullname"; } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartLegentType"].ToString() == "3") { LegendField = "ProductLineDesc"; } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartLegentType"].ToString() == "4") { LegendField = ""; } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartTypeDataShow"].ToString() == "1") { LabelType = "Label=#VAL"; } else { LabelType = "Label=#PERCENT"; } if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["IsChartBar"].ToString() == "True") { MainChart.DataBindCrossTable(Dt.AsEnumerable(), LegendField, Xfield, YField, "Label=Duration"); foreach (Series N in MainChart.Series) { N.AxisLabel = "ProductLineDesc"; N.BorderWidth = 2; } } else { MainChart.Series.Add("Default"); for (int i = 0; i < Dt.Rows.Count; i++) { MainChart.Series["Default"].Points.AddXY(Dt.DefaultView[i][Xfield].ToString(), Convert.ToInt32(Dt.DefaultView[i][YField])); } MainChart.Series[0].Legend = "Default"; MainChart.Series[0].IsVisibleInLegend = true; MainChart.Series[0].LegendText = "#VALX"; } try { if (IsRandomColor && BLL.Cls_PublicOperations.Dt.DefaultView[0]["IsChartBar"].ToString() == "True") { foreach (Series N in MainChart.Series) { // N.Color = System.Drawing.ColorTranslator.FromHtml("#" + generator.NextColour()); N.Color = System.Drawing.ColorTranslator.FromHtml("#" + generator.NextColour()); } } if (IsRandomColor && BLL.Cls_PublicOperations.Dt.DefaultView[0]["IsChartBar"].ToString() == "False") { for (int x = 0; x < MainChart.Series.Count; x++) { for (int i = 0; i < MainChart.Series[x].Points.Count; i++) { foreach (Series N in MainChart.Series) { // N.Color = System.Drawing.ColorTranslator.FromHtml("#" + generator.NextColour()); // N.Color = Random(); MainChart.Series[x].Points[i].Color = System.Drawing.ColorTranslator.FromHtml("#" + generator.NextColour()); } } } } else { for (int x = 0; x < MainChart.Series.Count; x++) { for (int i = 0; i < MainChart.Series[x].Points.Count; i++) { for (int j = 0; j < Dt.Rows.Count; j++) { if (Dt.DefaultView[j][LegendField].ToString() == MainChart.Series[x].Points[i].AxisLabel) { MainChart.Series[x].Points[i].Color = Color.FromArgb(Convert.ToInt32(Dt.DefaultView[j]["StateColor"].ToString())); // MainChart.Series[x].Color = Color.Red;// Color.FromArgb(Convert.ToInt32(Dt.DefaultView[j]["StateColor"].ToString())); } } } } } } catch { } try { foreach (Series N in MainChart.Series) { N.AxisLabel = "ProductLineDesc"; N.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartType"].ToString());// Enum.GetValues (typeof(SeriesChartType), "RangeBar");// System.Windows.Forms.DataVisualization.Charting.SeriesChartType( "System.Windows.Forms.DataVisualization.Charting.SeriesChartType.RangeBar") ; } } catch { } // MainChart.Series [Dt.DefaultView[i]["Fullname"].ToString()].Legend = "Default"; // MainChart.Series [Dt.DefaultView[i]["Fullname"].ToString()].LegendText = "#VALX"; } catch { } try { if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartLegentType"].ToString() == "4") { foreach (Series N in MainChart.Series) { N.IsVisibleInLegend = false; } } } catch { } // MainChart.Series[0].LegendText = "StartDate";// "#VALX"; //if ( BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartLegentType"].ToString() == "1") //{ // MainChart.Series[0].Legend = "Default"; // MainChart.Series[0].LegendText = "#VALX"; //} // MainChart.Series[0].YValueMembers = "Duration";// نمایش مقدار در قسمت Y // MainChart.Series[0].Points.DataBindXY(, ); // MainChart.Series[0].LabelToolTip = "!StartDate"; MainChart.ChartAreas.Add("Main Area"); MainChart.ChartAreas[0].BackColor = Color.Transparent; MainChart.Legends[0].BackColor = Color.Transparent; MainChart.Legends[0].Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Bottom; if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ShowChartCaption"].ToString() == "True") { MainChart.Titles.Add("Default"); MainChart.Titles[0].Text = BLL.Cls_PublicOperations.Dt.DefaultView[0]["Caption"].ToString(); MainChart.Titles[0].Visible = true; } try { if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartTypeDataShow"].ToString() == "1") { for (int x = 0; x < MainChart.Series.Count; x++) { for (int i = 0; i < MainChart.Series[x].Points.Count; i++) { MainChart.Series[x].Points[i].Label = "#VAL"; } } } } catch { } try { if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartTypeDataShow"].ToString() == "2") { for (int x = 0; x < MainChart.Series.Count; x++) { for (int i = 0; i < MainChart.Series[x].Points.Count; i++) { MainChart.Series[x].Points[i].Label = "#PERCENT"; } } } } catch { } try { if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartTypeDataShow"].ToString() == "3") { for (int x = 0; x < MainChart.Series.Count; x++) { for (int i = 0; i < MainChart.Series[x].Points.Count; i++) { MainChart.Series[x].Points[i].Label = ""; } } } } catch { } //if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ChartLegentType"].ToString() == "1") //{ // MainChart.Series[0].LegendText = "StartDate";// "#VALX"; //} //else //{ // MainChart.Series[0].LegendText = "StartDate";// "#VALX"; //} if (BLL.Cls_PublicOperations.Dt.DefaultView[0]["ShowChart3D"].ToString() == "True") { MainChart.ChartAreas[0].Area3DStyle.Enable3D = true; } // Set drawing style // MainChart.Series["Default"]["PieDrawingStyle"] = "SoftEdge"; // MainChart.Series["Default"].IsVisibleInLegend = true; //Lbl_ParameterDesc.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(255))))); //Lbl_ParameterDesc.Location = new System.Drawing.Point(8, 7); //Lbl_ParameterDesc.Name = "Lbl_ParameterDesc"; //Lbl_ParameterDesc.Size = new System.Drawing.Size(91, 26); //Lbl_ParameterDesc.TabIndex = 6; //Lbl_ParameterDesc.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; //if (Dt.Rows.Count > 0) //{ // decimal Data = Decimal.Parse(Utility.NZ(Dt.DefaultView[0][0].ToString(), 0).ToString()); // // Lbl_ParameterDesc.Text = Decimal.Round(Data, 2).ToString(); // if (BLL.Cls_PublicOperations.Dt.DefaultView[i]["ParameterName"].ToString().Trim().Contains("(%)")) // { // Lbl_ParameterDesc.Text = Decimal.Round(Data, 1).ToString(); // } // else // { // TimeSpan span = TimeSpan.FromSeconds(Convert.ToDouble(Data)); // string label = String.Format("{0:D2}:{1:D2}:{2:D2}:{3}", span.Days, span.Hours, span.Minutes, span.Seconds);// span.ToString(@"hh\:mm\:ss"); // Lbl_ParameterDesc.Text = label; // } //} //else //{ // Lbl_ParameterDesc.Text = "عدم خروجی دستور ایجاد شده"; //} //Lbl_ParameterDesc.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; //Pnl_State.Controls.Add(Lbl_ParameterCaption); //Pnl_State.Controls.Add(Lbl_ParameterDesc); // Pnl_Main.Controls.Add(Pnl_State); if (DtTrend.Rows.Count > 0) { int x = MainChart.Series.Count; for (int i = 0; i <= x - 1; i++) { DtTrend = TempTable.DefaultView.Table.Select(LegendField + "='" + MainChart.Series[i].Name + "' ").CopyToDataTable(); DtTrend = DtTrend.DefaultView.Table.Select("Fullname = '0' ").CopyToDataTable(); MainChart.Series.Add("زمان در دسترس " + MainChart.Series[i].Name); for (int j = 0; j < DtTrend.DefaultView.Table.Rows.Count; j++) { MainChart.Series["زمان در دسترس " + MainChart.Series[i].Name].Points.AddXY(DtTrend.DefaultView.Table.Rows[j][Xfield].ToString(), Convert.ToInt32(DtTrend.DefaultView.Table.Rows[j][YField])); MainChart.Series["زمان در دسترس " + MainChart.Series[i].Name].ChartType = SeriesChartType.Line; MainChart.Series["زمان در دسترس " + MainChart.Series[i].Name].Color = System.Drawing.ColorTranslator.FromHtml("#" + generator.NextColour()); } } } }