c# - 从柱形图中删除 x 和 y 轴

标签 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();
        }

最佳答案

我找到了解决方案..

        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;

关于c# - 从柱形图中删除 x 和 y 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27226424/

相关文章:

c# - 在没有 SQL Server 的情况下创建 C# 应用程序

c# - 下拉列表第一个值显示 "choose"

graph - 从 Erlang 中的有向循环图中的一个顶点找到所有可能的路径

algorithm - 通过顶点/节点的最小切割 - 而不是边缘

jquery - 气泡图将项目置于选择的顶部

charts - FLOT 中的对数图

c# - 使用 ProcessStartInfo 为 UAC 重定向标准输出和提示

c# - 如何使用反射调用扩展方法?

graph - Neo4j - 主节点和写锁

python - 使用 matplotlib 在 python 中使用字典的条形图