2016-12-21 5 views
0

グラフを描画するためにコアプロットを使用しています。私の問題は、凡例の文字色を線の色に合わせて設定したいのです。私は1つのグラフに4つの散布図があり、各散布図は異なる線の色を持っています。コアプロットを使用して凡例に異なる色のテキストを設定する方法

凡例では線の色が正しく表示されますが、散布図の各タイトルの線の色に合わせてテキストの色を変更したいと思います。私は伝説のために次のコードを書いています。伝説凡例内のすべてのテキストは、白色であるので、唯一のスタイルすなわちnewGraph.legend?.textStyle = dataSourceLabelStyleを取ることができることが理解される上記コードを形成するよう

newGraph.legend = CPTLegend(graph: newGraph) 
     newGraph.legend?.numberOfRows = UInt(2.0) 
     let dataSourceLabelStyle = CPTMutableTextStyle() 
     dataSourceLabelStyle.color = CPTColor.white() 
     newGraph.legend?.textStyle  = dataSourceLabelStyle 
     newGraph.legend?.fill = CPTFill(color: CPTColor.init(componentRed: 50/244, green: 43/244, blue: 87/244, alpha: 1.0)) 
     newGraph.legend?.cornerRadius = 5.0 
     newGraph.legendDisplacement = CGPoint.init(x: -50, y: 210) 
     let fadeInAnimation = CABasicAnimation(keyPath: "opacity") 
     fadeInAnimation.duration   = 1.0 
     fadeInAnimation.isRemovedOnCompletion = false 
     fadeInAnimation.fillMode   = kCAFillModeForwards 
     fadeInAnimation.toValue    = 1.0 
     dataSourceLinePlot.add(fadeInAnimation, forKey: "animateOpacity") 
     self.scatterGraph = newGraph 

凡例のテキストの色を線の色に合わせて変更したいと思います。

私はこれを手伝ってくれますか?

答えて

0

分散プロットを含むほとんどのプロットタイプでは、attributedTitleを希望の色属性のNSAttributedStringに設定します。円グラフと棒グラフには、データインデックスごとに帰属凡例タイトルを提供するデータソースメソッドがあります。

+0

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

0

グラフの凡例を設定し、グラフにすべてのプロットが含まれている可能性があるとは思わないでください。私はObjCでこれをどのように使用しているのですか。

CPTScatterPlot *aPlot = [[CPTScatterPlot alloc] init]; 
    aPlot.dataSource = self; 
    aPlot.identifier = stringPlotId; 
    [graph addPlot:aPlot toPlotSpace:plotSpace]; 
aPlot.title=stringPlotTitle;//will show in legends 

//add more plots if needed then format labels text once for all plots 

graph.legend= [CPTLegend legendWithGraph:graph]; 
CPTMutableTextStyle *mySmallerTextStyle = [[CPTMutableTextStyle alloc] init]; 
[mySmallerTextStyle setFontSize:8]; 
mySmallerTextStyle.color=[CPTColor whiteColor]; 
[graph.legend setTextStyle:(CPTTextStyle *)mySmallerTextStyle]; 
関連する問題