Jump to content

Display image based on condition.


Rahul Singh 6

Recommended Posts

Hello,

I'm fairly new to Spotfire and my apologies if this sounds stupid.

I have a calculated field(%), that I want to use for passing custom images. Basically, if the value is below 50%, the image should be rain, if 50-70; cloud, if above 70, a sun. I would want this to be as diverse as possible for future use, i,e, have more than 3 criteria images.

Is this possible in Spotfire If it is , can you point me towards a tutorial or documentation

Thanks,

Link to comment
Share on other sites

If you are looking to change the images in a text area based on selection. Then you can use the below script as a reference to dynamically change the images

from Spotfire.Dxp.Application.Visuals import *

from System.IO import *

from System.Drawing import *

from System.Drawing.Imaging import *

from System.Text.RegularExpressions import *

#from System.Drawing.Imaging.ImageFormat import *

 

vis=txtArea.As[HtmlTextArea]()

 

 

 

image1 = Image.FromFile(r"C:SourceJapan.png");

image2 = Image.FromFile(r"C:SourceSpain.png");

image3 = Image.FromFile(r"C:SourceFrance.png");

 

image1Exists=vis.Images.Contains("Japan")

image2Exists=vis.Images.Contains("Spain")

image3Exists=vis.Images.Contains("France")

 

if not image1Exists:

vis.Images.Add("Japan",image1,ImageFormat.Png)

if not image2Exists:

vis.Images.Add("Spain",image2,ImageFormat.Png)

if not image3Exists:

vis.Images.Add("France",image3,ImageFormat.Png)

 

content=vis.HtmlContent

 

#check if image is already present

htmlImage=content.Contains("img src")

#Get which Image

imageName=Document.Properties["showImage"]

if htmlImage:

#code to replace the image

input = vis.HtmlContent;

oldValue = Regex.Match(input, ""(.+)"").Groups[1].Value;

print oldValue

input = input.Replace(oldValue,imageName );

#print input

vis.HtmlContent=input

print vis.HtmlContent

else:

addImage= ""

vis.HtmlContent=addImage+content

Link to comment
Share on other sites

I stumbled upon this while researching but this isn't what I'm looking for.

 

I'm trying to set criteria, that if [Field1] is less than 0.3, show [image1], for 0.3-0.6 show [image2] and so on.

 

I just want it to be a standalone chart that shows the image and that's all. I will put it next to a KPI block.

 

 

 

Any idea how I can achieve this

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...