我在用 ms chart ,用于绘制 K线图。。目前,我遇到问题了,本来,数据里面,肯定是x轴和y轴一一对应的,比如:x y
1 1.1
2 1.2
2.1 1.3
3 2
...我想要的结果是:x轴的数据固定显示,比如, 最大值是 3500,间隔 500 显示一条主刻度线,那么 X轴应该显示:500,1000,1500,2000,2500,3000,3500。其中,500-1000的范围之内,可能没有数据,但是,也要显示为空。。也就是,不管有木有数据,X轴都是有 7个 点,整个图表,固定分为7列 。然后,都在这其中的范围之内描点。我查了很多资料,都没搞定,请问,你们有木有人 搞过 ms chart控件,给我个思路,或者示例 。。不要推荐我 使用 其他控件,我就是 要用 ms chart 谢谢了。。
1 1.1
2 1.2
2.1 1.3
3 2
...我想要的结果是:x轴的数据固定显示,比如, 最大值是 3500,间隔 500 显示一条主刻度线,那么 X轴应该显示:500,1000,1500,2000,2500,3000,3500。其中,500-1000的范围之内,可能没有数据,但是,也要显示为空。。也就是,不管有木有数据,X轴都是有 7个 点,整个图表,固定分为7列 。然后,都在这其中的范围之内描点。我查了很多资料,都没搞定,请问,你们有木有人 搞过 ms chart控件,给我个思路,或者示例 。。不要推荐我 使用 其他控件,我就是 要用 ms chart 谢谢了。。
解决方案 »
- asp.net中 如何用multiview 控件和menu 控件制作【竖向】选项卡?
- 客户端导出excel,保存对话框中没有.xlsx选项
- 通过API获取新浪微博的帐号或者邮箱?
- unable to start debugging on the web server
- sql2005示例数据库AdventureWork下载
- 如何解决Infragistics NetAdvantage的WebNavBar控件不能和vs2005的master页面一起工作的问题
- 关于身份验证与框架页面矛盾的问题?
- 今天我们学校上不起网,我死了。不能按期完成任务了。这下我又得请朋友帮助我了。先谢谢了
- 在asp.net中listbox控件的多选
- forms 认证方式验证登录,拒绝匿名用户访问某个文件夹里的内容,但是我发现该文件夹的图片等文件非登录用户也能访问,如何限制非登录用户的访问权限
- ASP.NET做日程提醒
- 关于二次开发,三层架构的问题
{
Chart1.Series[0].Points.AddY(0);
//设置X轴
Chart1.ChartAreas[0].AxisX.Interval = 500;
Chart1.ChartAreas[0].AxisX.Maximum = 3500;
Chart1.ChartAreas[0].AxisX.Minimum = 500;
//设置y轴
Chart1.ChartAreas[0].AxisY.Interval = 20;
Chart1.ChartAreas[0].AxisY.Maximum = 100;
}
this.chart1.ChartAreas[0].AxisX.Interval = 500;
this.chart1.ChartAreas[0].AxisX.Maximum = 3500;
this.chart1.ChartAreas[0].AxisX.Minimum = 0;
this.chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount;
设置一下series的XValueType的数据类型!!
#region 生成K线图
private void button4_Click(object sender, EventArgs e)
{
if (dt.Columns.Count > 1)
{
string bname = dt.Columns[0].ColumnName.Trim();//X轴数据
string cname = dt.Columns[1].ColumnName.Trim();//Y轴数据 DataTable dt1 = CreateTable();
this.chart1.DataSource = dt;//dt 是全局变量,datatable类型
int count = 350; if (this.chart1.Series.Count > 0)
{
this.chart1.Series.Remove(this.chart1.Series[cname]);
}
this.chart1.Series.Add(cname); if (this.chart1.ChartAreas.Count > 0)
{
this.chart1.ChartAreas.Remove(this.chart1.ChartAreas["ChartArea1"]);
}
this.chart1.ChartAreas.Add("ChartArea1");//增加图表区 if (dt.Columns.Count > 2)
{
string xname = dt.Columns[0].ColumnName.Trim();//X轴数据
string yname = dt.Columns[2].ColumnName.Trim();//Y轴数据 this.chart1.DataSource = dt; if (this.chart1.Series.Count > 0)
{
this.chart1.Series.Remove(this.chart1.Series[yname]);
}
this.chart1.Series.Add(yname); if (this.chart1.ChartAreas.Count > 1)
{
this.chart1.ChartAreas.Remove(this.chart1.ChartAreas["ChartArea2"]);
}
this.chart1.ChartAreas.Add("ChartArea2");//增加图表区
this.chart1.Series[yname].ChartArea = "ChartArea2";
this.chart1.ChartAreas[1].AxisX.Title = xname;
this.chart1.ChartAreas[1].AxisY.Title = yname; this.chart1.Series[yname].ChartType = SeriesChartType.Spline;
this.chart1.Series[yname].XValueMember = xname;
this.chart1.Series[yname].YValueMembers = yname;
//chart1.Series["Series1"].Points.DataBindXY(dt.DefaultView, "x", dt.DefaultView, "y");
} this.chart1.Series[cname].ChartArea = "ChartArea1";
this.chart1.ChartAreas[0].AxisX.Title = bname;
this.chart1.ChartAreas[0].AxisY.Title = cname;
//this.chart1.ChartAreas[0].BackColor = Color.FromArgb(209, 237, 254); // 坐标轴设置
this.chart1.ChartAreas[0].AxisY.IsMarginVisible = false;
// 坐标轴刻度线不延长出来设置
this.chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
this.chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
//X 次要辅助线设置
this.chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
//X 次要辅助线间距
//this.chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 500;
//X 次要辅助线颜色
this.chart1.ChartAreas[0].AxisX.MinorGrid.LineColor = Color.LightGray;
//Y 次要辅助线设置
this.chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = true;
//Y 次要辅助线间距
this.chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 5;
//Y 次要辅助线颜色
this.chart1.ChartAreas[0].AxisY.MinorGrid.LineColor = Color.LightGray;
//X 主要辅助线设置
this.chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
//X 主要辅助线间距
//this.chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 500;
//X 主要辅助线颜色
this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Black;
//Y 主要辅助线设置
this.chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
//Y 主要辅助线间距
this.chart1.ChartAreas[0].AxisY.MajorGrid.Interval = 5;
//Y 主要辅助线颜色
this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Black;
//X 轴坐标最大最小值
this.chart1.ChartAreas[0].AxisX.Interval = 500;
this.chart1.ChartAreas[0].AxisX.Maximum = 3500;
this.chart1.ChartAreas[0].AxisX.Minimum = 0;
//this.chart1.ChartAreas[0].AxisX.MaximumAutoSize = 100;
this.chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount;
this.chart1.ChartAreas[0].AxisY.Interval = 5;
//图例位置、字体设置;坐标轴位置设定
//this.chart1.Legends[0].Position = new ElementPosition(10, 10, 88, 7);
//this.chart1.Legends[0].Font = new Font("宋体", 9);
//this.chart1.ChartAreas[0].InnerPlotPosition = new ElementPosition(6, 5, 90, 82); this.chart1.Series[cname].ChartType = SeriesChartType.Spline;
this.chart1.Series[cname].XValueMember = bname;
this.chart1.Series[cname].YValueMembers = cname;
this.chart1.Series[cname].XValueType = ChartValueType.Double;
this.chart1.Series[cname].YValueType = ChartValueType.Double; //chart1.Series[cname].Points.DataBindXY(dt1.DefaultView, "x", dt.DefaultView, cname);
this.chart1.DataBind();
}
}
#endregion
double[] x = { 500, 605.9718, 611.95203, 617.98438, 624.00958, 1014.0288 };
double[] y = { 19.7936, 19.7376, 19.834349, 19.755239, 18.81985, 21.722811 };
Chart1.Series[0].Points.DataBindXY(x, y);
Chart1.ChartAreas[0].AxisX.Interval = 500;
Chart1.ChartAreas[0].AxisX.Maximum = 3500;
Chart1.ChartAreas[0].AxisX.Minimum = 0;
是完全没问题的!!楼主的CreateTable()不知是调用的是什么!
将DataTable转成DataView试试!
DataView myView = new DataView(dt1);
Chart1.Series[0].Points.DataBindXY(myView, "x轴字段", myView, "yx轴字段");//绑定