【问题标题】:ASP.NET Bar Chart labelsASP.NET 条形图标签
【发布时间】:2016-03-20 09:00:57
【问题描述】:

在我的项目中,我有一个包含 12 个条形的条形图。该图表每 2 个条形显示 x 轴标签。我想要每个酒吧的标签。 我怎样才能做到这一点 ?

public ActionResult TekenGrafiek(ApplicationUser user, string naam)
    {
        Product p = user.Verlanglijst.Producten.First(pr=>pr.Artikelnaam == naam);
        int totaal = p.AantalInCatalogus;
        DateTime[] weken = new DateTime[12];
        int[] aantal = new int[12];
        DateTime nu = DateTime.Now.StartOfWeek(DayOfWeek.Monday);
        for (int j = 0; j < 11; j++)
        {
            weken[j] = nu;
            aantal[j] = p.GeefAantalReserveerbaarInPeriode(nu, nu.AddDays(7));
            nu = nu.AddDays(7);
        }
        Bitmap image = new Bitmap(300, 50);
        Graphics g = Graphics.FromImage(image);
        Chart c = new Chart();
        ChartArea a = new ChartArea();

        a.AxisX.MajorGrid.Enabled = false;
        a.ShadowColor = Color.DeepSkyBlue;
        a.BackColor = Color.AliceBlue;
        c.Titles.Add("Aantal beschikbaar komende weken");
        c.ChartAreas.Add(a);
        c.Width = 1000;
        c.Height = 250;
        Series mySeries = new Series();
        mySeries.Points.DataBindXY(weken, aantal);
        mySeries.IsValueShownAsLabel = true;
        c.Series.Add(mySeries);

        MemoryStream imageStream = new MemoryStream();
        c.SaveImage(imageStream, ChartImageFormat.Png);
        c.TextAntiAliasingQuality = TextAntiAliasingQuality.SystemDefault;
        Response.ContentType = "image/png";
        imageStream.WriteTo(Response.OutputStream);
        g.Dispose();
        image.Dispose();
        return null;
    }

代码是用 C# ASP.NET MVC 编写的。这是此时的图表

【问题讨论】:

    标签: c# asp.net asp.net-mvc charts


    【解决方案1】:

    之前有人问过类似的question
    尝试使用

    a.AxisX.Interval = 1;
    

    我相信这会有所帮助。 祝你好运。

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多