MS CHART我如何显示Points.AddXY值 [英] MS CHART howe do I display the Points.AddXY value

查看:203
本文介绍了MS CHART我如何显示Points.AddXY值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Win Forms应用程序中添加了一个MS Chart组件,并且在大多数情况下它的工作效果非常好。我有两个问题:



#1 - 每当我选择一个新元素时,一些StripLine值仍然会出现。这只发生在一些元素上,我找不到为什么会发生这种情况的共同点。什么时候触发事件,我做的第一件事就是Element.Series.Clear();这应该从前一个事件中删除任何数据。



#2 - 我需要将要添加的点的实际值放在Y轴上。目前,我使用MarkerStyle.Circle将坐标显示为圆形。我想将值放在圆圈上方。我试图使用AxisLabel属性,但它正在替换图表区域底部的列标题属性。我怀疑我应该使用不同的房产。



这是代码



I added an MS Chart component to my Win Forms application and for the most part it works and looks pretty good. I am having two issues:

#1 - whenever I select a new element, some of the StripLine values are still showing up. This only happens for some elements and I can't find a common denominator why this happens. When ever the event is triggered , the first thing I do is Element.Series.Clear(); which should remove any data from the previous event.

#2 - I need to place the actual value of the point being added to the Y axis. Currently I show the coordinate as a circle using MarkerStyle.Circle. I would like to place the value above the circle. I attempted to use the AxisLabel property but it is replacing the column header property on the bottom portion of the chart area. I suspect I should be using a different property.

Here's the code

       int blockSize = 30;
       // clear the chart
       Element.Series.Clear();

       // fill the chart
       var series = Element.Series.Add("My Series");
       series.ChartType = SeriesChartType.Line;
       series.XValueType = ChartValueType.Int32;

       int counter = 0;
       int cnt = 0;

       var chartArea = Element.ChartAreas[series.ChartArea];

       Element.Series["My Series"].BorderWidth = 3;
       Element.Series["My Series"].MarkerStyle = MarkerStyle.Circle;
       Element.Series["My Series"].MarkerSize = 10;
       Element.Series["My Series"].SmartLabelStyle.Enabled = true;
       series.Points.Clear();

       foreach( DataGridViewColumn col in dataGridView1.Columns)
       {
           if (row.Cells[counter].Value != null && counter > 0)
           {
               series.Points.AddXY(col.HeaderText, row.Cells[counter].Value.ToString());
               // the following line overwrites the column Header text
             //  series.Points[cnt].AxisLabel = row.Cells[counter].Value.ToString();


                if (Convert.ToDouble(row.Cells[counter].Value.ToString()) < minVal)
                {
                    minVal = Convert.ToDouble(row.Cells[counter].Value.ToString());
                }

                if (Convert.ToDouble(row.Cells[counter].Value.ToString()) > maxVal)
                {
                    maxVal = Convert.ToDouble(row.Cells[counter].Value.ToString());
                }

                cnt += 1;
           }
               counter += 1;
       }



       // set view range to [0,max]
       chartArea.AxisX.Minimum = 1;
       chartArea.AxisX.Maximum = cnt;


       chartArea.AxisY.Minimum = minVal;
       chartArea.AxisY.Maximum = maxVal;

       // enable autoscroll
       chartArea.CursorX.AutoScroll = true;

       // let's zoom to [0,blockSize] (e.g. [0,100])
       chartArea.AxisX.ScaleView.Zoomable = true;
//       chartArea.AxisX.ScaleView.SizeType = DateTimeIntervalType.Number;
       int position = 0;
       //  int size = blockSize;
       int size = 10;
       chartArea.AxisX.ScaleView.Zoom(position, size);

       // disable zoom-reset button (only scrollbar's arrows are available)
       chartArea.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;

       // set scrollbar small change to blockSize (e.g. 100)
       chartArea.AxisX.ScaleView.SmallScrollSize = blockSize;

 StripLine stripLine = new StripLine();
// chartArea.AxisY.StripLines.Remove(stripLine);
 stripLine.IntervalOffset = mminVal;
 stripLine.StripWidth = stripLine.StripWidth = (mmaxVal - mminVal);
 stripLine.TextAlignment = StringAlignment.Near;
 stripLine.ForeColor = Color.Red;
 stripLine.Text = "Normal Range";
 stripLine.BackColor = Color.LightPink;
 stripLine.BorderColor = Color.Red;
 stripLine.BorderDashStyle = ChartDashStyle.Dash;
 stripLine.BorderWidth = (int)1.5;
 stripLine.BackHatchStyle = ChartHatchStyle.LightDownwardDiagonal;
 chartArea.AxisY.StripLines.Add(stripLine);

推荐答案

这篇关于MS CHART我如何显示Points.AddXY值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆