如何在C#中绘制折线图, [英] How do I draw line chart in C#,
本文介绍了如何在C#中绘制折线图,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
namespace VistaBalanceAlgorithms
{
public class VerticalForce
{
public static float SteadyStateTotalForce = 1;
public static bool SteadyState = false;
public VerticalForce(float[] frameValues)
{
Left = 0;
Right = 0;
Total = 0;
if (frameValues != null)
{
float leftForce = frameValues.Take(frameValues.Length / 2).Sum();
float rightForce = frameValues.Skip(frameValues.Length / 2).Sum();
Left = (int)((leftForce / SteadyStateTotalForce) * 100);
Right = (int)((rightForce / SteadyStateTotalForce) * 100);
Left = Left < 0 ? 0 : Left;
Right = Right < 0 ? 0 : Right;
Total = Left + Right;
}
}
public int Left { get; protected set; }
public int Right { get; protected set; }
public int Total { get; protected set; }
}
public class VerticalForceGraph
{
private List<VerticalForce> vtfList = new List<VerticalForce>();
public int BufferSize { get; set; }
public void Add(VerticalForce vtf)
{
vtfList.Add(vtf);
}
public void Reset() { vtfList.Clear(); }
public int Count {get{return vtfList.Count;} }
public float[] GetLeftVTF()
{
return vtfList.Select(x => (float)x.Left).ToArray();
}
public float[] GetLeftVTF(int startPoint, int count)
{
return vtfList.GetRange(startPoint, count).Select(x => (float)x.Left).ToArray();
}
public float[] GetRightVTF()
{
return vtfList.Select(x => (float)x.Right).ToArray();
}
public float[] GetRightVTF(int startPoint, int count)
{
return vtfList.GetRange(startPoint, count).Select(x => (float)x.Right).ToArray();
}
public float[] GetTotalVTF()
{
return vtfList.Select(x => (float)x.Total).ToArray();
}
public float[] GetTotalVTF(int startPoint, int count)
{
return vtfList.GetRange(startPoint, count).Select(x => (float)x.Total).ToArray();
}
}
}
我想调用这些方法并为每个绘制折线图
我尝试过的方法:
这是我的mainform.cs
I want to call these methods and draw line chart for each
What I have tried:
This is my mainform.cs
private void toolStripMenuItemVtfGraphicalView_Click(object sender, EventArgs e)
{
m_viewMode = viewModes.VTF_GRAPHICAL_VIEW;
panelHeatMap.viewMode = m_viewMode;
toolStripDropDownViewMode.Text = toolStripMenuItemVtfGraphicalView.Text;
chart1.Visible = true;
for (int i = 10; i < 100; i += 50)
{
chart1.Series["Left Vtf"].Points.AddXY(vtfGraph.GetLeftVTF(),i);
chart1.Series["Right Vtf"].Points.AddXY(vtfGraph.GetRightVTF(),i);
chart1.Series["Total Vtf"].Points.AddXY(vtfGraph.GetTotalVTF(),i);
}
}
推荐答案
MSDN提供了一个基本的使用System.Windows.Forms.DataVisualization.Charting的教程,以下链接引用Visual Studio 2012;
MSDN - 教程:创建基本图表
[ ^ ]
更详细的版本;
MSDN:图表控件 [ ^ ]
我在MVC网站中使用.Net Framework 4.5等价物它适用于我需要的东西
亲切的问候
MSDN provides a basic tutorials using System.Windows.Forms.DataVisualization.Charting, the below links refer to Visual Studio 2012;
MSDN - Tutorial: Creating a Basic Chart
[^]
More detailed version;
MSDN: Chart Controls[^]
I am using the .Net Framework 4.5 equivalent in an MVC site & it works for what I need
Kind Regards
这篇关于如何在C#中绘制折线图,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文