【问题标题】:Alignment of ASP.NET ChartASP.NET 图表的对齐方式
【发布时间】:2014-12-05 13:42:52
【问题描述】:

我使用经典的 asp.net 图表来呈现一些数据,然后将其放入 PDF。我似乎无法解决的一个问题是,当我将图例添加到图表的右侧时,它会被向下推。谁能明白为什么?

        _chart.Height = _chartHeight;
    _chart.Width = _chartWidth;

    Legend legend = new Legend("Default");
    legend.LegendStyle = LegendStyle.Column;
    legend.IsTextAutoFit = false;
    legend.Docking = Docking.Right;
    legend.Alignment = System.Drawing.StringAlignment.Near;

    _chart.Legends.Add(legend);

    Series series = new Series("Default");
    _chart.Series.Add(series);

    ChartArea chartArea = new ChartArea("ChartArea1");
    //chartArea.Position.Y = 0;
    _chart.ChartAreas.Add(chartArea);
    //-- this data would usually be collected from _travelRepository.TravelModesForTheYear 
    //-- but for speed I've hardcoded as its same for everyone in country 
    _chart.Series["Default"].Points.DataBindXY(xValues, yValues);

    System.Drawing.Color[] colours = new System.Drawing.Color[] { _orange, _yellow, _pink, _red, _green, _purple };

    int i = 0;
    foreach (System.Web.UI.DataVisualization.Charting.DataPoint point in _chart.Series["Default"].Points)
    {
        _chart.Series["Default"].Points[i].Color = colours[i];
        if(showLegends)
            _chart.Series["Default"].Points[i].Label = "#PERCENT";

        i++;
    }

    _chart.Series["Default"].ChartType = SeriesChartType.Pie;

    _chart.Series["Default"]["PieLabelStyle"] = showLegends ? "Inside" : "Disabled";
    _chart.Series["Default"].LabelForeColor = System.Drawing.Color.White;
    _chart.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
    _chart.ChartAreas["ChartArea1"].AlignmentStyle = AreaAlignmentStyles.Position;
    _chart.BorderlineWidth = 0;
    _chart.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled = showLegends;
    _chart.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = showLegends;
    _chart.ChartAreas["ChartArea1"].AlignmentOrientation = AreaAlignmentOrientations.Horizontal;
    _chart.Legends[0].Enabled = showLegends;

【问题讨论】:

    标签: asp.net asp.net-charts system.web.ui.webcontrols


    【解决方案1】:

    您可以设置图例的 Position 和 IsDockedInsideChartArea。 ChartArea 本身也可以定位,因此它不会四处移动。您必须对这些值进行一些调整才能使其正确。

    legend.Position.X = 0
    legend.Position.Y = 0
    legend.IsDockedInsideChartArea = False
    
    area.Position.Height = 94
    area.Position.Width = 98
    area.Position.Y = 0
    area.Position.X = 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-05
      • 2013-08-23
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 2011-06-20
      • 1970-01-01
      • 2015-10-25
      相关资源
      最近更新 更多