如何更改echarts默认颜色

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何更改echarts默认颜色相关的知识,希望对你有一定的参考价值。

参考技术A 设置option属性:xAxis.axisLine.lineStyle.color
参考资料:
ps:问题类写错

如何从默认的蓝色更改标签栏图标颜色?

【中文标题】如何从默认的蓝色更改标签栏图标颜色?【英文标题】:How to change tabbar icon color from default blue? 【发布时间】:2011-04-27 05:01:49 【问题描述】:

我有四个标签。我能够将标签图标颜色从默认的蓝色更改为红色(或者可能是任何颜色),并且效果很好。问题是它只适用于三个 tabbaritems,最后一个是默认的蓝色。下面是代码。我在rootviewcontrollerAppDelegate.m 中对此进行了编码,您可以通过将以下代码粘贴到您的 appdelegate 中来尝试此操作。你们能帮帮我吗,我会很高兴的!

@implementation UITabBar (ColorExtensions)

- (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur



CGColorRef cgColor = [color CGColor];

 CGColorRef cgShadowColor = [shadowColor CGColor];

for (UITabBarItem *item in [self items])

 if ([item respondsToSelector:@selector(selectedImage)] &&

    [item respondsToSelector:@selector(setSelectedImage:)] &&

       [item respondsToSelector:@selector(_updateView)])



CGRect contextRect;

  contextRect.origin.x = 0.0f;

 contextRect.origin.y = 0.0f;

 contextRect.size = [[item selectedImage] size];
            // Retrieve source image and begin image context

 UIImage *itemImage = [item image];

 CGSize itemImageSize = [itemImage size];

 CGPoint itemImagePosition; 

 itemImagePosition.x = ceilf((contextRect.size.width - itemImageSize.width) / 2);

  itemImagePosition.y = ceilf((contextRect.size.height - itemImageSize.height) / 2);

 UIGraphicsBeginImageContext(contextRect.size);

  CGContextRef c = UIGraphicsGetCurrentContext();
            // Setup shadow

  CGContextSetShadowWithColor(c, shadowOffset, shadowBlur, cgShadowColor);
            // Setup transparency layer and clip to mask

  CGContextBeginTransparencyLayer(c, NULL);

 CGContextScaleCTM(c, 1.0, -1.0);

 CGContextClipToMask(c, CGRectMake(itemImagePosition.x, -itemImagePosition.y, 

    itemImageSize.width, -itemImageSize.height), [itemImage CGImage]);
            // Fill and end the transparency layer

 CGContextSetFillColorWithColor(c, cgColor);

 contextRect.size.height = -contextRect.size.height;

    CGContextFillRect(c, contextRect);

  CGContextEndTransparencyLayer(c);
            // Set selected image and end context

  [item setSelectedImage:UIGraphicsGetImageFromCurrentImageContext()];

  UIGraphicsEndImageContext();
            // Update the view

 [item _updateView];




@end

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions 
    

    [[tabBarController tabBar] recolorItemsWithColor:[UIColor redColor] shadowColor:[UIColor blackColor] shadowOffset:CGSizeMake(0.0f, -1.0f) shadowBlur:3.0f];

    [self.window addSubview:tabBarController.view];

        [self.window makeKeyAndVisible];

        [self addTabBarArrow];

         return YES;

【问题讨论】:

【参考方案1】:
 [[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];

【讨论】:

【参考方案2】:

感谢您的分享。

但在具有视网膜显示屏的 iPhone4 或 iPod4 上部署时存在一些缺陷。 tarBar 中选中的图标会比未选中的小。

所以我想在这里分享我的修复:

CGSize orginalSize = [[item selectedImage] size];
double scaleFactor = 1;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) 
    scaleFactor = [[UIScreen mainScreen] scale];

    contextRect.size = CGSizeMake(orginalSize.width*scaleFactor, orginalSize.height*scaleFactor);

// Retrieve source image and begin image context
UIImage *itemImage = [item image];
double imageScale = 1;
if ([itemImage respondsToSelector:@selector(scale)]) 
    imageScale = itemImage.scale;

CGSize itemImageSize = CGSizeMake(itemImage.size.width*imageScale, itemImage.size.height*imageScale);

如果我错了,请免费告诉我:)

【讨论】:

【参考方案3】:

自行添加tabbar-item没问题,我测试了这个代码4个项目;

但是您的最后一个标签栏项目是系统标签栏项目(“....”“更多”项目),所以这段代码可能没有用;它只是不使用您设置的图像;

【讨论】:

谢谢人...我遇到了另一个问题..上面的代码只适用于一个应用程序..我在其他应用程序中尝试了相同的代码它可以工作...你试试这个stuff.probably..in some other application...然后回复我【参考方案4】:
@implementation MoreViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    
        self.title = @"More";
        self.tabBarItem.image=[UIImage imageNamed:@"more.png"]; // here more.png is Yellow Image
    
    return self;


//.......
@end

【讨论】:

【参考方案5】:

转到您的资产文件夹,找到资产并单击 Identity Inspector ,然后将“渲染为”更改为原始图像

【讨论】:

以上是关于如何更改echarts默认颜色的主要内容,如果未能解决你的问题,请参考以下文章

echarts更改折线图区域颜色折线颜色折点颜色

echarts更改坐标轴文字颜色及大小

echarts tooltip 自定义formatter怎么设置颜色

Echarts 地图 省份的颜色自定义如何设置?

Echarts饼图更改颜色显示数据且换行

如何使用百度echarts炫光特效地图