private void loadinfo() { int i = 0; clsExcelReader er = new clsExcelReader(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\";//初始路径 openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { er.FileName = openFileDialog.FileName; } er.SheetNumber = 1; if (er.OpenFileContinuously() == false) { label1.Text = er.ErrorString; return; } int iCount = er.RowCount; for (i = 0; i < iCount - 2; i++) { pork Pork = new pork(); Pork.name = er.getTextInOneCell(i + 3, 20); string priceA = er.getTextInOneCell(i + 3, 7); if (priceA.IndexOf('-') == -1) { Pork.price = Convert.ToDouble(er.getTextInOneCell(i + 3, 7)); } else { Pork.price = Convert.ToDouble(priceA.Substring(0, priceA.IndexOf('-'))); } Pork.date = er.getTextInOneCell(i + 3, 18).Substring(0, 9); porklist.Add(Pork); } label1.Text = porklist.Count.ToString(); }
private void button1_Click(object sender, EventArgs e) { clsExcelReader er = new clsExcelReader(); //打开文件对话框 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\";//初始路径 openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { er.FileName = openFileDialog.FileName; } // textBox1.Text = er.FileName; er.SheetNumber = 1; if (er.OpenFileContinuously() == false) { textBox1.Text = er.ErrorString; return; } int iCount = er.RowCount; string[] listMonth = new string[iCount - 2]; clsChartPoint[] listPrice = new clsChartPoint[iCount - 3]; for (int i = 0; i < iCount - 3; i++) { listPrice[i] = new clsChartPoint(); //列号是指定的 listPrice[i].PointValue = Convert.ToDouble(er.getTextInOneCell(i + 3, 3)); listPrice[i].PointName = er.getTextInOneCell(i + 3, 1); } er.CloseFile(); this.AddIntoChart(listPrice, chart1); //设置Chart的滚动条: //设置滚动条是在外部显示 chart1.ChartAreas["ChartArea1"].AxisX.ScrollBar.IsPositionedInside= false; //设置滚动条的宽度 chart1.ChartAreas["ChartArea1"].AxisX.ScrollBar.Size = 20; //滚动条只显示向前的按钮,主要是为了不显示取消显示的按钮 chart1.ChartAreas["ChartArea1"].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll; //设置图表可视区域数据点数,说白了一次可以看到多少个X轴区域 chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size = 10; //设置滚动一次,移动几格区域 chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.MinSize = 2; //设置X轴的间隔,设置它是为了看起来方便点,也就是要每个X轴的记录都显示出来 chart1.ChartAreas["ChartArea1"].AxisX.Interval=2; //X轴起始点 chart1.ChartAreas["ChartArea1"].AxisX.Minimum = 0; //X轴结束点,一般这个是应该在后台设置的, chart1.ChartAreas["ChartArea1"].AxisX.Maximum = 19; //对于我而言,是用的第一列作为X轴,那么有多少行,就有多少个X轴的刻度,所以最大值应该就等于行数; //该值设置大了,会在后边出现一推空白,设置小了,会出后边多出来的数据在图表中不显示,所以最好是在后台根据你的数据列来设置.要实现显示滚动条,就不能设置成自动显示刻度,必须要有值才可以。 }