问题遇到的现象和发生背景
我正在做一个C#的上位机,需要画曲线图,我画出的如下图所示
我希望能做到以下三点:
1、在上图红圈中,坐标轴的刻度是在坐标轴上
2、在曲线图的上方和右方也要有刻度线
3、在下面的代码基础上修改
希望做出类似这样的图像
问题相关代码,请勿粘贴截图
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace chartTest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series.Clear();
Series DataTest=new Series("数据测试1");
DataTest.ChartType = SeriesChartType.Spline;
DataTest.Points.AddXY(1, 20);
DataTest.Points.AddXY(4, 20);
DataTest.Points.AddXY(6, 10);
Series DataTest2 = new Series("数据测试2");
DataTest2.ChartType = SeriesChartType.Spline;
DataTest2.Points.AddXY(1, 12);
DataTest2.Points.AddXY(3, 24);
DataTest2.Points.AddXY(7, 28);
DataTest2.Color= Color.Blue;
DataTest2.IsValueShownAsLabel= true;
chart1.ChartAreas[0].AxisX.Maximum = 7;
chart1.ChartAreas[0].AxisX.Title = "横坐标";
chart1.ChartAreas[0].AxisY.Title = "纵坐标";
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Transparent;
//chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle=ChartDashStyle.DashDotDot;
chart1.ChartAreas[0].AxisX.MinorGrid.LineColor = Color.Transparent;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Transparent;
chart1.ChartAreas[0].AxisY.MinorGrid.LineColor = Color.Transparent;
chart1.Series.Add(DataTest);
chart1.Series.Add(DataTest2);
}
}
}