gpt4 book ai didi

c# - C# 中的简单条形图

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:57 24 4
gpt4 key购买 nike

我想问一下是否可以使用 MCharts 创建两个简单的条形图,如下所示:

Screen shot http://img16.imageshack.us/img16/4413/desktoptf.png

我想要上图的精确复制品,所以没有图表或网格,只有两个像这样的简单条形图。

另一件事是,最大值由条形两端的红色小条纹表示,并且应该一直保持到超过最大值为止。

我的想法是我正在读取应该动态应用于条形图的实时数据(4 个值)。

那么有人知道如何去做吗?我目前正在使用 MScharts 插件(或者使用 C# 的绘画功能而不是 MScharts 会更好吗?)。

提前致谢。

编辑:

好的,这是我想出的:

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;


namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

bool k = false;
Random random = new Random();
int max = 0;

protected override void OnPaint(PaintEventArgs paintEvnt)
{
int i = 30;
Graphics gfx = paintEvnt.Graphics;
Pen myPen = new Pen(Color.Black);

for (i = 40; i < 640; i = i + 100)
{
gfx.DrawLine(myPen, i, 25, i, 35);
}

for (i = 40; i < 640; i = i + 100)
{
gfx.DrawLine(myPen, i, 55, i, 65);
}

Color brushColor = Color.FromArgb(0, 0, 255);
SolidBrush myBrush = new SolidBrush(brushColor);

int randomnumber = random.Next(0, 601);
gfx.FillRectangle(myBrush, 33, 33, randomnumber, 25);

if (randomnumber + 33 > max)
{
max = randomnumber + 33;
gfx.DrawLine(new Pen(Color.Red, 3), max, 30, max, 60);
}
else
{
gfx.DrawLine(new Pen(Color.Red, 3), max, 30, max, 60);
}
}

private void button1_Click(object sender, EventArgs e)
{
this.Invalidate();
}
}
}

这就是它的样子:http://img411.imageshack.us/img411/5646/graphmj.jpg每次按下按钮时,都会生成新的随机数据并覆盖旧图形。但是,仍然存在问题。红色指示器应该只有在超过最大值时才会增加,这就是我尝试在 OnPaint 方法中使用 if-query 实现的,但它有时仍会构成随机值并完全消失,超过旧值尽管新的随机值更低..这没有意义。

下面是项目,以防有人想尝试并帮助我: http://up.k10x.net/ambglolrngulg/LevelMeter.zip

我真的很无能,因为代码对我来说看起来是正确的。

最佳答案

我不会为此使用 mschart。我会编写一个控件来执行条形图和最大值指示器,然后在另一个用户控件上使用它来获取标签和内容。最后我看了 .net 中没有形状控制,所以这可能会给你一些线索。 open source .net shape control

关于c# - C# 中的简单条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8152599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com