在过去的几天里,我试图使用MS图表控件来绘制我的sql服务器上的StockData(1分钟间隔,烛台)。我认为它会变得容易......但是现在我很快就要哭了。
如果有人可以解决任何问题,我会遇到很多问题,他永远都会受到祝福:每当我改变
series.XValueType = ChartValueType.Time;
滚动条不再正常工作,我不能再拖动了,但我可以 指向滚动条上的某个位置它会带我到那里,但是当它是普通的int索引时,我无法顺利地拖动它。
我滚动不同的小时(分钟)我有严重的问题 在Y轴上,我在开始时设置了最大值和最小值但是效果不是很好 当你滚动图表时。
我设置的每个点(在填充循环中)
series.Points[index]["PriceUpColor"] = "Green";
series.Points[index]["PriceDownColor"] = "Red";
但无论如何,所有的蜡烛都是红色的。
点击时我有一个按钮,我想要填充图表,但事实并非如此 工作,只有我把我的代码放在form_load
我设置了轴lbl
chartArea.AxisX.LabelStyle.Format = "hh:mm";
这是正确的代码吗?
当我有浮动值(例如:26.52),但是当我把这些值放在 series.Points.AddXY,字符上的结果将是26.5273287623当然没有帮助,我尝试了很多不同的解决方案(铸造,删除数字我自己等) 但无法找到解决方案
最后 这是我的代码,我在我的表单上放了一个图表,我调用此函数来更改图表设置并填充(我已经做错了吗?)
我意识到这很长,我能说什么,谢谢你的帮助! (欢迎大家帮忙!)
private void MyChart(Chart chart1, DailyBarData dbb)
- >获取图表组件和dailybardata,理论上应相应地填充图表 - > iv也插入一些随机数据
{
int viewSize = 30;
chart1.Series.Clear();
var series = chart1.Series.Add("Price");
series.ChartType = SeriesChartType.Candlestick;
series.YValueType = ChartValueType.Auto;
series.XValueType = ChartValueType.Time;
DateTime date = dbb.Bars[0].time.AddMinutes (1); //getting the first minute
double viewdistanceDouble = date.AddMinutes(viewSize).ToOADate(); // getting the initital X loc - im guessing this is not good
double startdateDouble = date.ToOADate();
double maxy = 0; //minmax values for the chart
double miny = 10000000;
for (int index = 0; index < dbb.Count()-1; index++)
{
BarData b = dbb.Bars[index];
series.Points.AddXY(
b.time, // X value is a date
b.TwoDigits (b.High), // High Y value - is originally a float, here i mult by 100, cast to int then double then divide by 100
//and gets the exact same result..... i realize this is unneeded but i cant solve it
b.TwoDigits(b.Low), // Low Y value
b.TwoDigits(b.Open), // Open Y value
b.TwoDigits(b.Close)); // Close Y value
if (b.Low < miny) miny = b.Low;
if (b.High > maxy) maxy = b.High;
// u can use this code instead, however those values are ints and not floats which is half of the problem
// with this values i get less problems
//series.Points.AddXY(
// date, // X value is a date
// rnd.Next(40, 50), // High Y value
// rnd.Next(10, 20), // Low Y value
// rnd.Next(20, 40), // Open Y value
// rnd.Next(20, 40)); // Close Y value
//date = date.AddMinutes(1);
series.Points[index]["PriceUpColor"] = "Green"; // this code have unclear effects as it always red
series.Points[index]["PriceDownColor"] = "Red";
series.Points[index].Color = Color.Black;
series.Points[index].BorderColor = Color.Black;
}
var chartArea = chart1.ChartAreas[series.ChartArea];
chartArea.AxisX.LabelStyle.Format = "hh:mm";
chartArea.AxisX.Interval = 5;
chartArea.AxisX.IntervalType = DateTimeIntervalType.Minutes;
chartArea.AxisX.ScaleView.Zoom(startdateDouble, viewdistanceDouble); //starting scale , rarly works
chartArea.AxisX.ScaleView.SmallScrollSize = viewSize;
chartArea.AxisX.ScrollBar.IsPositionedInside = true;
chartArea.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
chartArea.AxisY.Maximum = maxy ; //by the values found on the loop, not good i want it to be automated when u scroll
chartArea.AxisY.Minimum = miny;
}
答案 0 :(得分:3)
编辑:1可以试试
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DataVisualization.Charting.DateTimeIntervalType.Milliseconds;
或其他类型。