当前位置:编程学习 > C#/ASP.NET >>

有关zedgraph的 问题

我现在想要zedgraph控件在C#中画一条折线,横轴是质量,纵轴是浓度,现在我已经完成了横轴坐标为[0,2500,4250,5250,5750],纵轴与之对应的坐标为[0,50,75,100,125],画出这条折线!由于小弟是初学者,知道这个问题对各位来说很简单,还请各位不吝赐教,写上详细代码!小弟不胜感激。。。在线等着各位的回复。。。 --------------------编程问答-------------------- http://blog.csdn.net/happy09li/article/details/7535388 --------------------编程问答--------------------
引用 1 楼  的回复:
http://blog.csdn.net/happy09li/article/details/7535388

您好,我看了一下您之前发的传值的贴子,我没有看懂,想请教您一下:我在Form1中定义了一个数组,想在Form2中调用Form1中这个数组的值,请问具体代码怎么写?谢谢!!! --------------------编程问答--------------------
你把数组传过去就可以了啊


1.在Form2里定义

public int[] str{get;set;}

Form2中就可以用Form1中的数组了 也就是str

2. 在Form1里创建Form2对象,

Form2 f = new Form2();
f.str=//你要传的值
f.Show();
--------------------编程问答--------------------
引用 3 楼  的回复:
你把数组传过去就可以了啊


1.在Form2里定义

public int[] str{get;set;}

Form2中就可以用Form1中的数组了 也就是str

2. 在Form1里创建Form2对象,

Form2 f = new Form2();
f.str=//你要传的值
f.Show();

大哥,还请您指点迷津,我按您的说法去做了,但是显示有错误 --------------------编程问答-------------------- 哪里错误?
你能把你的代码贴出来 --------------------编程问答--------------------
引用 5 楼  的回复:
哪里错误?
你能把你的代码贴出来

Form1: 
for (int m = 0; m < c.Length; m++)
            {
                c[m] = array[m];
                //dataGridView1.Rows[m].Cells[0].Value = Convert.ToInt32(c[m]);
                form2a.str1[m] = c[m];
            }
 for (int m = 0; m < c.Length - 1; m++)
            {
                for (int n = 0; n < dataGridView1.Rows.Count; n++)
                {
                    if (c[m] >= select_arrry[2 * n] && c[m + 1] <= select_arrry[2 * n + 1])
                    {
                        SumFlimt[m] += Flimt[n];
                        SumMass[m] = SumFlimt[m] * (c[m + 1] - c[m]);

                    }
                    else
                        continue;

                }
                CumMass += SumMass[m];
                cummass[m + 1] = CumMass;
                TheoryFlimt[m] = (double)(CumMass / c[m + 1]);
            }
            for(int d=0;d<c.Length;d++)
            {
                form2a.str2[d] = cummass[d];//你要传的值
                
            }
 form2a.Show();
Form2:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;

namespace 数据界面
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public int[] str1 { get; set; }

        public double[] str2 { get; set; }
        
        public void Form2_Load(object sender, EventArgs e)
        {
            
            // Get a reference to the GraphPane instance in the ZedGraphControl
            GraphPane myPane = zg1.GraphPane;
            
            // Set the titles and axis labels
            myPane.Title.Text = "Water Pinch Graph";
            myPane.XAxis.Title.Text = "MassLoad(g/h)";
            myPane.YAxis.Title.Text = "Impurity Density(mg/L)";
            //myPane.Y2Axis.Title.Text = "Parameter B";

            // Make up some data points based on the Sine function
            PointPairList list = new PointPairList();
            PointPairList list2 = new PointPairList();

            for (int i = 0; i < str1.Length; i++)
            {
                double x = (double)str1[i];
                double y = (double)str2[i];
                //double x = (double)i * 5.0;
                //double y = Math.Sin((double)i * Math.PI / 15.0) * 16.0;
                //double y2 = y * 13.5;
                list.Add(x, y);
                //list2.Add(x, y2);
            }

            // Generate a red curve with diamond symbols, and "Alpha" in the legend
            LineItem myCurve = myPane.AddCurve("Alpha",
                list, Color.Red, SymbolType.Diamond);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Generate a blue curve with circle symbols, and "Beta" in the legend
            myCurve = myPane.AddCurve("Beta",
                list2, Color.Blue, SymbolType.Circle);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;

            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            // Manually set the axis range
            myPane.YAxis.Scale.Min = -30;
            myPane.YAxis.Scale.Max = 30;

            // Enable the Y2 axis display
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale blue
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;

            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);

            // Add a text box with instructions
            TextObj text = new TextObj(
                "Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse",
                0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom);
            text.FontSpec.StringAlignment = StringAlignment.Near;
            myPane.GraphObjList.Add(text);

            // Enable scrollbars if needed
            zg1.IsShowHScrollBar = true;
            zg1.IsShowVScrollBar = true;
            zg1.IsAutoScrollRange = true;
            zg1.IsScrollY2 = true;

            // OPTIONAL: Show tooltips when the mouse hovers over a point
            zg1.IsShowPointValues = true;
            zg1.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler);

            // OPTIONAL: Add a custom context menu item
            zg1.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler(
                            MyContextMenuBuilder);

            // OPTIONAL: Handle the Zoom Event
            zg1.ZoomEvent += new ZedGraphControl.ZoomEventHandler(MyZoomEvent);

            // Size the control to fit the window
            SetSize();

            // Tell ZedGraph to calculate the axis ranges
            // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets
            // up the proper scrolling parameters
            zg1.AxisChange();
            // Make sure the Graph gets redrawn
            zg1.Invalidate();
        }

        /// <summary>
        /// On resize action, resize the ZedGraphControl to fill most of the Form, with a small
        /// margin around the outside
        /// </summary>
        private void Form2_Resize(object sender, EventArgs e)
        {
            SetSize();
        }

        private void SetSize()
        {
            zg1.Location = new Point(10, 10);
            // Leave a small margin around the outside of the control
            zg1.Size = new Size(this.ClientRectangle.Width - 20,
                    this.ClientRectangle.Height - 20);
        }

        /// <summary>
        /// Display customized tooltips when the mouse hovers over a point
        /// </summary>
        private string MyPointValueHandler(ZedGraphControl control, GraphPane pane,
                        CurveItem curve, int iPt)
        {
            // Get the PointPair that is under the mouse
            PointPair pt = curve[iPt];

            return curve.Label.Text + " is " + pt.Y.ToString("f2") + " units at " + pt.X.ToString("f1") + " days";
        }

        /// <summary>
        /// Customize the context menu by adding a new item to the end of the menu
        /// </summary>
        private void MyContextMenuBuilder(ZedGraphControl control, ContextMenuStrip menuStrip,
                        Point mousePt, ZedGraphControl.ContextMenuObjectState objState)
        {
            ToolStripMenuItem item = new ToolStripMenuItem();
            item.Name = "add-beta";
            item.Tag = "add-beta";
            item.Text = "Add a new Beta Point";
            item.Click += new System.EventHandler(AddBetaPoint);

            menuStrip.Items.Add(item);
        }

        /// <summary>
        /// Handle the "Add New Beta Point" context menu item.  This finds the curve with
        /// the CurveItem.Label = "Beta", and adds a new point to it.
        /// </summary>
        private void AddBetaPoint(object sender, EventArgs args)
        {
            // Get a reference to the "Beta" curve IPointListEdit
            IPointListEdit ip = zg1.GraphPane.CurveList["Beta"].Points as IPointListEdit;
            if (ip != null)
            {
                double x = ip.Count * 5.0;
                double y = Math.Sin(ip.Count * Math.PI / 15.0) * 16.0 * 13.5;
                ip.Add(x, y);
                zg1.AxisChange();
                zg1.Refresh();
            }
        }

        // Respond to a Zoom Event
        private void MyZoomEvent(ZedGraphControl control, ZoomState oldState,
                    ZoomState newState)
        {
            // Here we get notification everytime the user zooms
        }


    }
} --------------------编程问答-------------------- 要不您给我您的QQ,然后我请求远程协助,可以吗?谢谢 --------------------编程问答--------------------
引用 6 楼  的回复:
引用 5 楼  的回复:
哪里错误?
你能把你的代码贴出来

Form1: 
for (int m = 0; m < c.Length; m++)
            {
                c[m] = array[m];
                //dataGridView1.Rows[m].Cells[0].Value = Convert.ToInt……



for (int m = 0; m < c.Length; m++)
  {
  c[m] = array[m];
  //dataGridView1.Rows[m].Cells[0].Value = Convert.ToInt32(c[m]);
  form2a.str1[m] = c[m];
  }
form2a.str2[d] = cummass[d];//你要传的值???


这句你都有问题?你是要把数组传到from2是把,你的数组C呢? C[m]是什么你知道么?
你那些代码时从哪里copy的?


把传值的2个地方改下,,

Form1:  
for (int m = 0; m < c.Length; m++)
  {
  c[m] = array[m];
  //dataGridView1.Rows[m].Cells[0].Value = Convert.ToInt32(c[m]);
  form2a.str1= c;
  }
 for (int m = 0; m < c.Length - 1; m++)
  {
  for (int n = 0; n < dataGridView1.Rows.Count; n++)
  {
  if (c[m] >= select_arrry[2 * n] && c[m + 1] <= select_arrry[2 * n + 1])
  {
  SumFlimt[m] += Flimt[n];
  SumMass[m] = SumFlimt[m] * (c[m + 1] - c[m]);

  }
  else
  continue;

  }
  CumMass += SumMass[m];
  cummass[m + 1] = CumMass;
  TheoryFlimt[m] = (double)(CumMass / c[m + 1]);
  }
  for(int d=0;d<c.Length;d++)
  {
  form2a.str2 = cummass;//你要传的值
    
  }
 form2a.Show(); --------------------编程问答-------------------- C[m]我知道,因为代码太长,我就没往上放 --------------------编程问答-------------------- --------------------编程问答-------------------- http://sourceforge.net/projects/zedgraph/files/ --------------------编程问答--------------------
引用 9 楼  的回复:
C[m]我知道,因为代码太长,我就没往上放


?你知道,,那你说c[m]是什么? --------------------编程问答-------------------- 8楼的给你代码传值是没问题的,,再有问题就是你其他地方的问题了
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,