2017-03-03 2 views
0

私は、Teechartを使用してwinformsで3Dプロットを作成しています。チャートに最初のサーフェスを追加すると、凡例ボックスには凡例項目(値用)と色で塗りつぶされたボックスが表示されます。しかし、複数のサーフェスを追加すると、凡例の凡例項目ボックス(サーフェスを表す)が白くなります。私はそれらが表面/シリーズの色で満たされることを期待する。3D TeeChartの凡例の色を元のデータ系列の色に設定するにはどうすればいいですか?

私がtrueにtChart.Legend.FontSeriesColor

を設定することにより、凡例項目のテキストの色を設定するために管理しているが、私は伝説を埋める方法を見つけ出すことができませんでした色付きの箱。

私は両方のシナリオのスクリーンショット添付した -

One surfaceを。 Two surfaces

ありがとうございました。

サンプルコードは:それはセルを描画するためにColorRangeを使用する場合

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シリーズは、ブラシなし凡例シンボルを描画します。
あなたは伝説のシンボルで描画されるように、一連の色を強制する場合は、あなたが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

関連する問題