2017-03-03 36 views
0

我正在使用Teechart在winforms中創建3D圖。將第一個曲面添加到圖表時,圖例框會顯示帶有填充顏色框的圖例項目(對於值)。但是,當我添加多個曲面時,圖例中的圖例項目框(代表曲面)是白色的。我期望他們充滿表面/系列顏色。如何將3D TeeChart中的legendbox的顏色設置爲基礎數據系列的顏色?

我設法通過設置

tChart.Legend.FontSeriesColor

爲真,設置圖例項文本的顏色,但我想不出如何填寫傳說有顏色的箱子。

我重視這兩種方案的截圖 -

One surfaceTwo surfaces

謝謝大家。

樣品的編號:

public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
      DisplayChart(); 
     } 

     private void DisplayChart() 
     { 
      tChart1.Series.Clear(); 
      tChart1.Legend.FontSeriesColor = true; 
      CreateSurface(new Plot3DSurface("X", "Y", "Z", new List<double> { 1.0, 2.0, 3.0 }, new List<double> { 3, 4, 7 }, new List<double> { 3, 5, 7 }, GetPoints(3, 3), "First", Color.Blue)); 
      CreateSurface(new Plot3DSurface("X", "Y", "Z", new List<double> { 1.0, 3.0, 6.0 }, new List<double> { 3, 5, 8 }, new List<double> { 5, 8, 10.5 }, GetPoints(3, 3), "Second", Color.Green)); 

     } 


     private static List<Point> GetPoints(int x, int y) 
     { 
      var points = new List<Point>(); 

      for (var p = 0; p < x; p++) 
      { 
       for (var t = 0; t < y; t++) 
       { 
        points.Add(new Point(p, t)); 
       } 
      } 

      return points; 

     } 
     private void CreateSurface(IPlot3DSurface surfaceInfo) 
     { 
      Custom3D surface; 

      var xCount = surfaceInfo.IndexesUsed.Select(index => index.X).Distinct().Count(); 
      var yCount = surfaceInfo.IndexesUsed.Select(index => index.Y).Distinct().Count(); 


      if (xCount < 2 || yCount < 2) 
      { 
       surface = new Points3D(tChart1.Chart); 
      } 
      else 
      { 
       surface = new Surface(tChart1.Chart) 
       { 
        Title = surfaceInfo.Title, 
        WireFrame = false, 
        DotFrame = false, 
        UseColorRange = true, 
        UsePalette = false, 
        ColorEach = false, 
        IrregularGrid = true, 
        PaletteStyle = PaletteStyles.Strong, 
        StartColor = surfaceInfo.Color, 
        Color = surfaceInfo.Color, 

       }; 
      } 

      DrawPoints(surfaceInfo, surface); 

     } 

     private void DrawPoints(IPlot3DSurface surfaceInfo, Custom3D surface) 
     { 
      foreach (var point in surfaceInfo.IndexesUsed) 
      { 
       surface.Add(surfaceInfo.GetXValue(point.X), surfaceInfo.GetZValue(point.X), surfaceInfo.GetYValue(point.Y)); 

      } 
     } 
    } 

public class Plot3DSurface : IPlot3DSurface 
    { 
     public Plot3DSurface(string xCoordinatePropertyName, string yCoordinatePropertyName, string zCoordinatePropertyName, 
      List<double> dataSourceListXCoordinate, List<double> dataSourceListYCoordinate, List<double> dataSourceZCoordinate, 
      List<Point> dataSourceIndexList, string title, Color color) 
     { 
      DataSourceListXCoordinate = dataSourceListXCoordinate; 
      DataSourceListYCoordinate = dataSourceListYCoordinate; 

      DataSourceListZCoordinate = dataSourceZCoordinate; 

      XCoordinatePropertyName = xCoordinatePropertyName; 
      YCoordinatePropertyName = yCoordinatePropertyName; 
      ZCoordinatePropertyName = zCoordinatePropertyName; 

      Title = title; 
      Color = color; 

      IndexesUsed = dataSourceIndexList; 
     } 

     private List<Point> _indexesUsed; 

     public List<Point> IndexesUsed 
     { 
      get 
      { 
       if (_indexesUsed != null) return _indexesUsed; 

       var ind = new List<Point>(); 

       for (var i = 0; i < DataCountXCoordinate; i++) 
        for (var j = 0; j < DataCountYCoordinate; j++) 
         ind.Add(new Point(i, j)); 

       return ind; 
      } 
      private set { _indexesUsed = value; } 
     } 

     private IList<double> DataSourceListXCoordinate { get; set; } 

     private IList<double> DataSourceListYCoordinate { get; set; } 

     private IList<double> DataSourceListZCoordinate { get; set; } 

     private int DataCountXCoordinate 
     { 
      get { return DataSourceListXCoordinate.Count; } 
     } 

     private int DataCountYCoordinate 
     { 
      get { return DataSourceListYCoordinate.Count; } 
     } 

     private string XCoordinatePropertyName { get; set; } 

     private string YCoordinatePropertyName { get; set; } 

     private string ZCoordinatePropertyName { get; set; } 

     public string XCoordinatePropertyDisplayName 
     { 
      get { return XCoordinatePropertyName + " (" + DataSourceListXCoordinate[0] + ")"; } 
     } 

     public string YCoordinatePropertyDisplayName 
     { 
      get { return YCoordinatePropertyName + " (" + DataSourceListYCoordinate[0] + ")"; } 
     } 

     public string ZCoordinatePropertyDisplayName 
     { 
      get { return ZCoordinatePropertyName + " (" + DataSourceListZCoordinate[0] + ")"; } 
     } 

     public string Title { get; private set; } 

     public Color Color { get; private set; } 

     public double? GetXValue(int i) 
     { 
      return DataSourceListXCoordinate[i]; 
     } 

     public double? GetYValue(int i) 
     { 
      return DataSourceListYCoordinate[i]; 
     } 

     public double? GetZValue(int i) 
     { 
      return DataSourceListZCoordinate[i]; 
     } 

     public double GetMinX 
     { 
      get { return DataSourceListXCoordinate.Min(v => v); } 
     } 

     public double GetMaxX 
     { 
      get { return DataSourceListXCoordinate.Max(v => v); } 
     } 

     public double GetMinY 
     { 
      get { return DataSourceListYCoordinate.Min(v => v); } 
     } 

     public double GetMaxY 
     { 
      get { return DataSourceListYCoordinate.Max(v => v); } 
     } 

     public double GetMinZ 
     { 
      get { return DataSourceListZCoordinate.Min(v => v); } 
     } 

     public double GetMaxZ 
     { 
      get { return DataSourceListZCoordinate.Max(v => v); } 
     } 



    } 

    public interface IPlot3DSurface 
    { 
     List<Point> IndexesUsed { get; } 

     string XCoordinatePropertyDisplayName { get; } 

     string YCoordinatePropertyDisplayName { get; } 

     string ZCoordinatePropertyDisplayName { get; } 

     string Title { get; } 

     double? GetXValue(int i); 

     double? GetYValue(int i); 

     double? GetZValue(int i); 

     double GetMinX { get; } 

     double GetMaxX { get; } 

     double GetMinY { get; } 

     double GetMaxY { get; } 

     double GetMinZ { get; } 

     double GetMaxZ { get; } 

     Color Color { get; } 
    } 

回答

1

Surface系列繪製的圖例符號而不刷時,它使用一個ColorRange繪製細胞。
如果要強制該系列顏色以圖例符號繪製,您可以使用OnSymbolDraw事件:

tChart1.Legend.Symbol.OnSymbolDraw += Symbol_OnSymbolDraw; 

與手動繪製的符號在裏面:

private void Symbol_OnSymbolDraw(object sender, SymbolDrawEventArgs e) 
{ 
    if (e.Series != null) 
    { 
    tChart1.Graphics3D.Brush.Color = e.Series.Color; 
    } 
    tChart1.Graphics3D.Rectangle(e.Rect); 
} 
+0

謝謝Yeray。有用。 – Manish

相關問題