private void saveToImageButton_Click(object sender, EventArgs e) { if (cartesianChart1 == null) { return; } var bitmap = ImageHelper.GetBitmap(cartesianChart1.Bounds.Width, cartesianChart1.Bounds.Height); cartesianChart1.DrawToBitmap(bitmap, cartesianChart1.Bounds); ImageHelper.SaveJpegWithCompression(bitmap, "hbk3.jpg".GetDesktopPath(), 95); }
private void buttonSaveGraph_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "png files (*.png)|*.png"; saveFileDialog.FilterIndex = 2; saveFileDialog.OverwritePrompt = false; saveFileDialog.RestoreDirectory = true; string path = null; if (saveFileDialog.ShowDialog() == DialogResult.OK) { path = saveFileDialog.FileName; Bitmap bmp = new Bitmap(chart.Width, chart.Height); chart.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); bmp.Save(path, ImageFormat.Png); showToastMessage(); } }
public static void AnalysisHuBeiK3() { // var f = "hbk3.txt".GetCommandLinePath(); // if (!File.Exists(f)) return; // var t = "hbk3_analysis.txt".GetCommandLinePath(); // if (File.Exists(t)) // { // File.Delete(t) //; // } // var ls = f.ReadAllText().Split('\n').Where(i => i.IsReadable()).Select(i => i.Trim()).OrderBy(i => i); // var sumList = ls.Select(i => i.Split(new char[] { ' ' }, 2).Last().Split(',').Select(iv => int.Parse(iv)).Sum()); var cartesianChart1 = new LiveCharts.WinForms.CartesianChart(); cartesianChart1.Size = new System.Drawing.Size(760, 1000); cartesianChart1.Dock = System.Windows.Forms.DockStyle.Fill; cartesianChart1.Location = new System.Drawing.Point(0, 0); cartesianChart1.Series = new SeriesCollection { new StackedColumnSeries { Values = new ChartValues <double> { 4, 5, 6, 8 }, StackMode = StackMode.Values, // this is not necessary, values is the default stack mode DataLabels = true }, new StackedColumnSeries { Values = new ChartValues <double> { 2, 5, 6, 7 }, StackMode = StackMode.Values, DataLabels = true } }; //adding series updates and animates the chart cartesianChart1.Series.Add(new StackedColumnSeries { Values = new ChartValues <double> { 6, 2, 7 }, StackMode = StackMode.Values }); //adding values also updates and animates cartesianChart1.Series[2].Values.Add(4d); cartesianChart1.AxisX.Add(new Axis { Title = "Browser", Labels = new[] { "Chrome", "Mozilla", "Opera", "IE" }, Separator = DefaultAxes.CleanSeparator }); cartesianChart1.AxisY.Add(new Axis { Title = "Usage", LabelFormatter = value => value + " Mill" }); var bitmap = ImageHelper.GetBitmap(760, 1000); cartesianChart1.DrawToBitmap(bitmap, cartesianChart1.Bounds); ImageHelper.SaveJpegWithCompression(bitmap, "hbk3.jpg".GetDesktopPath(), 95); //t.AppendAllText(string.Format("# 湖北快3 2015年11月3日至2018年6月9日共 {0} 期开奖统计" + Environment.NewLine + Environment.NewLine, ls.Count().ToString())); //var evenDictionary = new Dictionary<string, int>(); //var seqDictionary = new Dictionary<string, int>(); //var sumDictionary = new Dictionary<int, int>(); //evenDictionary.Add("大双", 0); //evenDictionary.Add("小双", 0); //evenDictionary.Add("大单", 0); //evenDictionary.Add("小单", 0); //seqDictionary.Add("三同号", 0); //seqDictionary.Add("连号", 0); //foreach (var sum in sumList) //{ // if (sum > 10) // { // if (sum % 2 == 0) // { // evenDictionary["大双"] += 1; // } // else // { // evenDictionary["大单"] += 1; // } // } // else // { // if (sum % 2 == 0) // { // evenDictionary["小双"] += 1; // } // else // { // evenDictionary["小单"] += 1; // } // } // //if (type == "三同号") // //{ // // seqDictionary["三同号"] += 1; // //} // //else if (type == "连号") // //{ // // seqDictionary["连号"] += 1; // //} // if (sumDictionary.Keys.Contains(sum)) // { // sumDictionary[sum] += 1; // } // else // { // sumDictionary.Add(sum, 1); // } //} //var sb = new StringBuilder(); //foreach (var item in evenDictionary) //{ // sb.AppendFormat("- {0}:开奖 {1} 次,{2}%" + Environment.NewLine, item.Key, item.Value, Math.Round((item.Value) / (double)ls.Count() * 100, 3)); //} //sb.AppendFormat("- {0}:开奖 {1} 次,{2}%" + Environment.NewLine, "双", evenDictionary["大双"] + evenDictionary["小双"], Math.Round((evenDictionary["大双"] + evenDictionary["小双"]) / (double)ls.Count() * 100, 3)); //sb.AppendFormat("- {0}:开奖 {1} 次,{2}%" + Environment.NewLine, "单", evenDictionary["大单"] + evenDictionary["小单"], Math.Round((evenDictionary["大单"] + evenDictionary["小单"]) / (double)ls.Count() * 100, 3)); //sb.AppendFormat("- {0}:开奖 {1} 次,{2}%" + Environment.NewLine, "大", evenDictionary["大双"] + evenDictionary["大单"], Math.Round((evenDictionary["大双"] + evenDictionary["大单"]) / (double)ls.Count() * 100, 3)); //sb.AppendFormat("- {0}:开奖 {1} 次,{2}%" + Environment.NewLine, "小", evenDictionary["小单"] + evenDictionary["小双"], Math.Round((evenDictionary["小单"] + evenDictionary["小双"]) / (double)ls.Count() * 100, 3)); //sb.AppendLine(); //sb.AppendLine(); //sb.AppendLine().AppendLine("## 和值").AppendLine(); //sumDictionary = sumDictionary.OrderByDescending(i => i.Value).ThenBy(i => i.Key).ToDictionary(i => i.Key, i => i.Value); //foreach (var item in sumDictionary) //{ // sb.AppendFormat("- {0}:开奖 {1} 次,{2}%" + Environment.NewLine, item.Key, item.Value, Math.Round((item.Value) / (double)ls.Count() * 100, 3)); //} //AnalysisSum(sumDictionary, sumList, sb); //AnalysisHuBeiK3EvenBig(sumList, sb); //AnalysisHuBeiK3EvenSmall(sumList, sb); //AnalysisHuBeiK3OddBig(sumList, sb); //AnalysisHuBeiK3OddSmall(sumList, sb); ////foreach (var item in seqDictionary) ////{ //// sb.AppendFormat("{0}:开奖 {1} 次,{2}%" + Environment.NewLine, item.Key, item.Value, Math.Round((item.Value) / (double)ls.Count() * 100, 3)); ////} //t.AppendAllText(sb.ToString()); }