簡體   English   中英

從柱狀圖中刪除x和y軸

[英]Remove x and y axis from Column chart

我正在使用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();
        }

我找到了解決方法..

        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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM