我正在尝试以编程方式创建图表。这是代码
static void Main(string[] args)
{
var xvals = new[]
{
new DateTime(2012, 4, 4),
new DateTime(2012, 4, 5),
new DateTime(2012, 4, 6),
new DateTime(2012, 4, 7)
};
var yvals = new[] { 1, 3, 7, 12 };
// create the chart
var chart = new Chart();
chart.Width = 600;
chart.Height = 350;
var chartArea = new ChartArea();
chartArea.AxisX.IsMarginVisible = false;
chartArea.AxisY.IsMarginVisible = false;
chartArea.AxisX.LabelStyle.Format = "dd";
chartArea.AxisX.MajorGrid.LineWidth = 0;
chartArea.AxisY.MajorGrid.LineWidth = 0;
chartArea.AxisY.LabelStyle.Font = new Font("Consolas", 8);
chartArea.AxisX.LabelStyle.Font = new Font("Consolas", 8);
chart.ChartAreas.Add(chartArea);
var series = new Series();
series.Name = "Series1";
series.ChartType = SeriesChartType.Line;
chart.Series.Add(series);
chart.Series["Series1"].Points.DataBindXY(xvals, yvals);
chart.SaveImage("chart.png", ChartImageFormat.Png);
}
我得到以下输出,
如何删除X和Y的轴线?所以我的输出只会是蓝线。
答案 0 :(得分:1)
chartArea.AxisY.LineWidth = 0;
chartArea.AxisX.LineWidth = 0;
chartArea.AxisX.LabelStyle.Enabled = false;
chartArea.AxisY.LabelStyle.Enabled = false;
chartArea.AxisX.MajorTickMark.Enabled = false;
chartArea.AxisY.MajorTickMark.Enabled = false;
解决了我的问题