c# - C# - 如何绘制具有 3 个变量的图表(Position[32]、ByteValue[255]、Frequency[int])
问题描述
我想绘制一个图表,显示每个位置中出现的字节值的频率。
//位置[32][结果[255][频率[int]
Dictionary<UInt16, Dictionary<UInt16, int>>
// 我想画这个
解决方案
MSChart 在这方面不是很擅长。
但是,如果您的某个维度只能处理几个不同的值,您可以使用其 3D 选项并为每个 z 值添加一个系列。
我假设您只有 32 个位置,并选择此维度作为 z 轴。
MSChart 并没有真正的 z 轴属性。但是如果为 a 启用了 3D,ChartArea
则将Series
其用作第 3 维。所以我添加了32系列..
然后我循环遍历 256 个值并或多或少地随机创建一个频率值。
以下是上述结果的代码:
private void button1_Click(object sender, EventArgs e)
{
chart1.Series.Clear();
SeriesChartType type = SeriesChartType.Point;
Random rnd = new Random(1);
ChartArea ca = chart1.ChartAreas[0];
ca.Area3DStyle.Enable3D = true;
ca.Area3DStyle.PointGapDepth = 500;
ca.Area3DStyle.PointDepth = 500;
for (int p = 0; p < 32; p++)
{
Series s = chart1.Series.Add("P" + p);
s.ChartType = type;
for (int v = 0; v < 256; v++)
{
// test data
int f = 25+(int)(rnd.Next(5) + 10*Math.Sin((p * (256 - v )/ 100f)));
s.Points.AddXY(v, f);
}
}
}
为了旋转,我对所有按钮使用了这个常见的点击事件:
private void btn_rotate_Click(object sender, EventArgs e)
{
int step = 10;
ChartArea ca = chart1.ChartAreas[0];
if (sender == btn_reset) { ca.Area3DStyle.Rotation = 30; ca.Area3DStyle.Inclination = 30; }
if (sender == btn_left && ca.Area3DStyle.Rotation < 180-step) ca.Area3DStyle.Rotation+= step;
if (sender == btn_right && ca.Area3DStyle.Rotation > -180-step) ca.Area3DStyle.Rotation-= step;
if (sender == btn_down && ca.Area3DStyle.Inclination < 90-step) ca.Area3DStyle.Inclination+= step;
if (sender == btn_up && ca.Area3DStyle.Inclination > -90-step) ca.Area3DStyle.Inclination-= step;
}
推荐阅读
- monit - 本地监控http状态
- python - 如何使用 Selenium-IDE 显示实际 URL
- android - 当我尝试获取用户设备位置时,Google Map 崩溃
- scala - 如何使用scala在databricks apache中旋转列和行?
- symfony - App\Security\LoginFormAuthenticator::getUser() 方法必须返回一个 UserInterface。您返回了 Softonic\GraphQL\Response
- c# - Blazor:对 EventCallback 使用动态时出现无效的参数类型匹配异常
- python - 计算 2d numpy 数组中包含另一个 1d 数组的所有元素的所有行的最佳方法?
- python - 通过 id 从 cosmosdb 中“获取”文档(不知道 _rid)
- postgresql - 时间戳比较查询实际上并没有过滤结果
- reactjs - vscode - 基于 react 和 react native 加载代码片段