从柱形图中删除x和y轴

时间:2014-12-01 10:32:19

标签: c# graph charts

我正在使用System.Web.UI.DataVisualization.Charting库在c#中生成柱形图。但我想删除x和y轴。只想要酒吧。我使用以下代码卸载网格线

        chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
        chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;

如何删除轴线及其值?

        var chart = new Chart
        {
            Width = 80,
            Height = 125,
            RenderType = RenderType.ImageTag,
            AntiAliasing = AntiAliasingStyles.All,
            TextAntiAliasingQuality = TextAntiAliasingQuality.High
        };

        chart.Titles.Add("50");
        chart.Titles.Add("Strongly Disagree");
        chart.Titles[0].Font = new Font("Arial", 8f,FontStyle.Bold);
        chart.Titles[0].ForeColor = Color.DarkGray;
        chart.Titles[1].Font = new Font("Arial", 7f);
        chart.Titles[1].ForeColor = Color.DarkGray;

        chart.Titles[0].Position.X = 50;
        chart.Titles[0].Position.Y = 50;

        chart.Titles[1].Position.X = 50;
        chart.Titles[1].Position.Y = 90;             

        chart.ChartAreas.Add("");            
        chart.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 12f);
        chart.ChartAreas[0].AxisY.TitleFont = new Font("Arial", 12f);
        chart.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Arial", 10f);
        chart.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
        chart.ChartAreas[0].BackColor = Color.White;
        chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
        chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;

        chart.Series.Add("");
        chart.Series[0].ChartType = SeriesChartType.Column;

        int i = 0;
        foreach (var q in myOrderList)
        {               
            if (i == 0)
            {
                chart.Series[0].Points.AddXY("", Convert.ToDouble(q.NumberOfOrders));
                chart.Series[0].Points[0].Color = Color.Orchid;
            }
            else
            {
                chart.Series[0].Points.AddXY("", Convert.ToDouble(q.NumberOfOrders));
                chart.Series[0].Points[1].Color = Color.DarkViolet;
            }
            i++;
        }
        using (var chartimage = new MemoryStream())
        {
            chart.SaveImage(chartimage, ChartImageFormat.Png);
            return chartimage.GetBuffer();
        }

1 个答案:

答案 0 :(得分:6)

我找到了解决方案..

        chart.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
        chart.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
        chart.ChartAreas[0].AxisX.MinorTickMark.Enabled = false;
        chart.ChartAreas[0].AxisX.Interval = 0;

        chart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
        chart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;

        chart.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
        chart.ChartAreas[0].AxisY.MinorTickMark.Enabled = false;

        chart.ChartAreas[0].AxisX.LineWidth = 0;
        chart.ChartAreas[0].AxisY.LineWidth = 0;