c# - 使用图表控件在两点之间画一条线

标签 c# winforms c#-4.0

如何在附图中的点(3,3)和点(1,1)之间画一条线。

这是一个图表控件。使用 c# 的 WinForms 应用程序

Chart example

private void Form1_Load(object sender, EventArgs e)
{

    //chart1 is the name of the chart control
    chart1.ChartAreas.Add("Area");
    chart1.ChartAreas["Area"].AxisX.Minimum = 0;
    chart1.ChartAreas["Area"].AxisX.Maximum = 10;
    chart1.ChartAreas["Area"].AxisX.Interval = 1;
    chart1.ChartAreas["Area"].AxisY.Minimum = 0;
    chart1.ChartAreas["Area"].AxisY.Maximum = 10;
    chart1.ChartAreas["Area"].AxisY.Interval = 1;


    chart1.Series.Add("Node");
    chart1.Series.Add("DG");
    chart1.Series["Node"].Color = Color.Blue;
    chart1.Series["DG"].Color = Color.Red;


    chart1.Series["Node"].Points.Add(new DataPoint(1, 1));
    chart1.Series["Node"].Points.Add(new DataPoint(8, 2));
    chart1.Series["DG"].Points.Add(new DataPoint(3, 3));

    chart1.Series["Node"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
    chart1.Series["DG"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
}

最佳答案

应该这样做;

        chart1.Series.Add("Line");
        chart1.Series["Line"].Points.Add(new DataPoint(1, 1));
        chart1.Series["Line"].Points.Add(new DataPoint(3, 3));
        chart1.Series["Line"].ChartType = SeriesChartType.Line;

关于c# - 使用图表控件在两点之间画一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15938278/

相关文章:

c# - 防止对话框在按钮的单击事件处理程序中关闭

.net - OPC : how to write a C# Hello World client? 新手指南

javascript - 不能有图表的实体是什么概念?

c# - 如何在不影响数据源的情况下交换 WPF 中已过滤数据网格中的行?

c# - 使用持久连接 c# 处理 HttpResponseMessage

c# - 由于 Unresolved 依赖关系,无法使用 Winforms 控件

c# - 如何通过反射过滤任何属性的集合?

vb.net - 从组合框中获取所选项目

c# - 如何从 C# 中的 app.config 获取一些元素?

c# - 按列排序的 Linq 查询摘要