お世話になります
visualStudioでグラフを作成しているのですが、特定範囲のグラフの背景色を変えたいのですがやりかたがわかりません。
c#
1using System; 2using System.Collections.Generic; 3using System.Drawing; 4using System.Text; 5using System.Windows.Forms; 6using System.IO; 7using System.Drawing.Imaging; 8using System.Windows.Forms.DataVisualization.Charting; 9 10namespace グラフ 11{ 12 public partial class Form1 : Form 13 { 14 public Form1() 15 { 16 InitializeComponent(); 17 } 18 19 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 24 List<string> list = new List<string>(); 25 26 //textファイル読み込み 27 StreamReader sr = new StreamReader("ファイル名", Encoding.Default); 28 while (sr.Peek() >= 0) 29 { 30 string line = ""; 31 32 while ((line = sr.ReadLine()) != null) 33 { 34 list.Add(line); 35 } 36 } 37 sr.Close(); 38 sr.Dispose(); 39 40 41 chart1.Series.Clear(); 42 chart1.Legends.Clear(); 43 chart1.ChartAreas.Clear(); 44 chart1.Hide(); 45 46 chart1.ChartAreas.Add(new ChartArea("1")); 47 48 49 50 // Seriesの作成 51 Series series1 = new Series(); 52 series1.ChartArea = "1"; 53 series1.ChartType = SeriesChartType.Line; 54 55 56 chart1.ChartAreas[0].AxisX.Minimum = DateTime.MinValue.AddHours(8).ToOADate(); 57 chart1.ChartAreas[0].AxisX.Maximum = DateTime.MinValue.AddHours(17).ToOADate(); 58 chart1.ChartAreas[0].AxisX.Interval = 1; 59 chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Hours; 60 chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Hours; 61 chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss"; 62 63 chart1.ChartAreas[0].AxisY.Maximum = 3; 64 chart1.ChartAreas[0].AxisY.Minimum = 1; 65 66 chart1.Series.Add(series1); 67 chart1.Series[0].ChartType = SeriesChartType.Line; 68 chart1.Series[0].XValueType = ChartValueType.Time; 69 chart1.Series[0].IsVisibleInLegend = false; 70 chart1.Series[0].IsValueShownAsLabel = false; 71 72 foreach (var line in list) 73 { 74 75 var xValue = DateTime.Parse("0001/01/01 " + " "+line.Split('\t')[0]); 76 var yValue = line.Split('\t')[1]; 77 var dp = new DataPoint(); 78 dp.SetValueXY(xValue, yValue); 79 dp.IsValueShownAsLabel = false; 80 chart1.Series[0].Points.Add(dp); 81 } 82 } 83 } 84}
Y軸が特定の範囲に入ったらその部分の背景に色を付けたいのですが可能でしょうか?
もしできるとしたら、どのようにしたらできるでしょうか?
よろしくお願いします
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/17 05:48
2020/01/17 05:55