2014-10-10 55 views
0

我使用經典的asp.net圖表來呈現一些數據,然後將其放入PDF中。我似乎無法解決的一個問題是,當我將圖例的右側添加到圖表的右側時,它會被推下。任何人都能看到爲什麼調整ASP.NET圖表

enter image description here

 _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; 

回答

0

您可以設置圖例的位置和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