I am using coreplot 0.9 .I had tried setting linecolor property for CPTLineStyle by
But it is giving error that color or fontSize is readonly property. Please give me some solution for this.
static CPTTextStyle *labelTextStyle= nil ;
labelTextStyle = [[CPTTextStyle alloc]init];
labelTextStyle.color =[CPTColor whiteColor];
labelTextStyle.fontSize = 10.0f ;
Use a CPTMutableTextStyle. In Core Plot, text styles, line styles, shadows, and numeric data objects come in two variants—mutable and immutable. This follows the pattern common to many Cocoa objects like NSString and NSArray.
Related
I am using the charts framework for iOS in Objective-C.
I am trying to plot data value labels (y values) on a chart which has 4 data sets. if there are 1, 2 or 3 data sets on my chart, the label values show up just fine. If I add a 4th data set, the label values do not show up at all.
I am using a NSMutableArray of UIColor objects for each dataset. I set the label color to [UIColor clearColor] when I don't want the label to show up and I set it to [UIColor whiteColor] when I do want it to show up, for each data point.
NSMutableArray *labelColors = [[NSMutableArray alloc] init];
for (NSDictionary *data in dataArray )
{
if (condition)
{
[labelColors addObject:UIColor.whiteColor];
}
else
{
[labelColors addObject:UIColor.clearColor];
}
}
dataSet.valueColors = labelColors;
Again, this technique works fine if I plot 1, 2, or 3 data sets on my X axis, but if I plot a 4th data set, it stops drawing labels completely. The way I have my chart set up, two data sets are on the left Y axis and two data sets are on the right Y axis.
Does anybody know why my labels are not showing?
I fixed this with one line in viewDidLoad where I first set up my chart.
_chartView.maxVisibleCount = 500;
I guess after adding the 4th data set I had more than the default value of maxVisibleCount (whatever that is) and when that happens no data labels are drawn regardless of other settings.
I figured this out when modifying my data set's drawValuesEnabled field and inside the auto complete text it said "this value is ignored when maxVisibleCount is reached".
I have currently subclassed NSLayoutManager along with other classes in the UITextView architecture in order to implement my own Word Processor like UITextView. I am currently facing a problem when trying to layout underlines under ranges of glyphs (to implement something like hyperlink). In order to layout the underlines I have overrode the following method in NSLayoutManager.
- (void)drawUnderlineForGlyphRange:(NSRange)glyphRange underlineType (NSUnderlineStyle)underlineVal baselineOffset:(CGFloat)baselineOffset lineFragmentRect:(CGRect)lineRect lineFragmentGlyphRange:(NSRange)lineGlyphRange containerOrigin:(CGPoint)containerOrigin
In the above method I compute the underline distance in points from origin of the underline to the end of the underline via the glyph range. View the following method:
- (void)getStartLocation:(CGFloat * _Nonnull )startLocation andEndLocation:(CGFloat * _Nonnull)endLocation ofGlyphsInRange:(NSRange)glyphRange {
NSRange characterRange = [self characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL];
(*startLocation) = [self locationForGlyphAtIndex:glyphRange.location].x;
CGGlyph glyphs[self.numberOfGlyphs];
NSUInteger numGlyphs = [self getGlyphsInRange:glyphRange glyphs:&glyphs[0] properties:NULL characterIndexes:NULL bidiLevels:NULL];
CTFontRef ctfont = [self getCTFontForGlyphsInRange:glyphRange];
double advances = CTFontGetAdvancesForGlyphs(ctfont, kCTFontOrientationDefault, &glyphs[0], NULL, numGlyphs);
(*endLocation) = (*startLocation) + (CGFloat)advances;}
As you can see I get the startLocation, and then I get the endLocation by summing the advances for each glyph in the glyphRange. This computation seems to work reasonably well but it seems to result in a overdrawn or underdrawn line for some sequences of characters. It has recently come to my attention that CTFontGetAdvancesForGlyphs does NOT account for font kerning. Can anyone help me with this code? How can I incorporate font kerning effectively into my computation? I have tried querying the NSKernAttribute in my NSTextStorage at the given location but I keep getting back nil values. I have tried both getting the attributeAtIndex and tried enumerating for the attribute over a range.
I am also aware NSAttributedString has underline options but I want to draw the underline myself for various reasons such as supporting custom defined styles, colors, and more.
In the iOS Charts library, unlike the BarChartDataSet class, the PieChartDataSet does not contain any property highlightAlpha that can be used to set a different alpha to the selected slice on the pie chart.
Although such a property can be introduced and using CGContextSetAlpha() we can modify the transparency of the highlighted slice, I want to do it without making any change in the library code. How can it be done?
I checked the code, currently, it does not support this.
public override func drawHighlighted(context context: CGContext, indices: [ChartHighlight])
{
...
CGContextSetFillColorWithColor(context, set.colorAt(xIndex).CGColor)
...
}
This just read data set color and use it to highlight. I think you are welcome to file a PR for such feature. Or I will do it when I have time.
For you, changing the source code seems the only option right now. That's why I think it's good for you to contribute.
For now, I have solved the problem using the delegate method:
- (void)chartValueSelected:(ChartViewBase * __nonnull)chartView
entry:(ChartDataEntry * __nonnull)entry
dataSetIndex:(NSInteger)dataSetIndex
highlight:(ChartHighlight * __nonnull)highlight
{
PieChartView *pPieChartView = (PieChartView *)chartView;
PieChartDataSet *pDataSet = (PieChartDataSet *)[pPieChartView.data.dataSets objectAtIndex:dataSetIndex];
NSMutableArray *pColors = [[NSMutableArray alloc] initWithArray:pDataSet.colors
copyItems:YES];
for (int nIndex = 0; nIndex < pColors.count; nIndex++) {
UIColor *pColor = [pColors objectAtIndex:nIndex];
if (nIndex == entry.xIndex) {
pColor = [pColor colorWithAlphaComponent:1];
}
else {
pColor = [pColor colorWithAlphaComponent:0.3];
}
[pColors replaceObjectAtIndex:nIndex
withObject:pColor];
}
pDataSet.colors = pColors;
}
In my case, I load the slices with alpha component less than 1. On highlighting the slice, the alpha value is changed to 1.
The same effect can be achieved if the highlightAlpha property is introduced in PieChartDataSet class. In the drawHighlighted method, CGContextSetAlpha(context, highlightAlpha) needs to be called. The BarChartDataSet has highlight colors as well, which are absent in PieChartDataSet.
Hi Can we get hash color string from UIImage ?
In below method if i pass [UIColor redColor] it is working , but if i pass
#define THEME_COLOR [UIColor colorWithPatternImage:[UIImage imageNamed:#"commonImg.png"]]
then it is not working.
+(NSString *)hexValuesFromUIColor:(UIColor *)color {
if (CGColorGetNumberOfComponents(color.CGColor) < 4) {
const CGFloat *components = CGColorGetComponents(color.CGColor);
color = [UIColor colorWithRed:components[0] green:components[0] blue:components[0] alpha:components[1]];
}
if (CGColorSpaceGetModel(CGColorGetColorSpace(color.CGColor)) != kCGColorSpaceModelRGB) {
return [NSString stringWithFormat:#"#FFFFFF"];
}
return [NSString stringWithFormat:#"#%02X%02X%02X", (int)((CGColorGetComponents(color.CGColor))[0]*255.0), (int)((CGColorGetComponents(color.CGColor))[1]*255.0), (int)((CGColorGetComponents(color.CGColor))[2]*255.0)];
}
Is there any other methods which can directly get Hash color from UIImage ?
You can't access the raw data directly, but by getting the CGImage of this image you can access it. Reference Link
You can't do it directly from the UIImage, but you can render the image into a bitmap context, with a memory buffer you supply, then test the memory directly. That sounds more complex than it really is, but may still be more complex than you wanted to hear.
If you have Erica Sadun's iPhone Developer's Cookbook there's good coverage of it from page 54. I'd recommend the book overall, so worth getting that if you don't have it.
I arrived at almost exactly the same code independently, but hit one bug that it looks like may be in Sadun's code too. In the pointInside method the point and size values are floats and are multiplied together as floats before being cast to an int. This is fine if your coordinates are discreet values, but in my case I was supplying sub-pixel values, so the formula broke down. The fix is easy once you've identified the problem, of course - just cast each coordinate to an int before multiplying - so, in Sadun's case it would be:
long startByte = ((int)point.y * (int)size.width) + (int)point.x) * 4;
Also, Sadun's code, as well as my own, are only interested in alpha values, so we use 8 bit pixels that take the alpha value only. Changing the CGBitMapContextCreate call should allow you to get actual colour values too (obviously if you have more than 8 bits per pixel you will have to multiply that in to your pointInside formula too).
OR
I've got a test Shinobi Control chart working but wnat to put a hoop, "O", at each data point.
How do you do this?
You need to set the point color on the series style object appropriately. The series which have the ability to show point (SChartScatterSeries, SChartLineSeries, SChartBandSeries) all have a pointStyle property within their style object, which is an instance of SChartPointStyle. This has the following relevant properties:
innerColor
color
innerRadius
outerRadius
showPoints
Depending on the effect you want (and the series type you are using) you need to set these appropriately. For example, to show 'hoops' on an SChartScatterSeries, you could use the following for the data source method:
- (SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(int)index
{
_series = [SChartColumnSeries new];
SChartScatterSeries *series = [SChartScatterSeries new];
series.style.pointStyle.innerColor = [UIColor whiteColor];
return series;
}
Note, if you're using SChartBandSeries or SChartLineSeries, these have showPoints set to NO by default, so you would need to set this to YES yourself.