我目前有以下d3代码。
<script>
var dataset = [14, 5, 26, 23, 9];
d3.select("body").selectAll("p")
.data(dataset)
.enter()
.append("p")
.text(function(d) {
if (d > 10)
{
return "Warning: Joe watched " + d + " cat vidoes today.";
}
else {
return "Joe watched " + d + " cat vidoes today.";
}});
如何使用外部CSS将{return“警告...”}部分变为红色? 非常感谢您的帮助!
答案 0 :(得分:3)
如果要使用外部css,则可以将文本元素与类关联:
"گدھا"
您还可以使用 public string Replacement(string input, string replacement)
{
string[] words = input.Split(' ');
string result = string.Empty;
for (int i = 0; i < words.Length; i++)
{
if(words[i].Contains('/'))
{
int barIndex = Reverse(words[i]).LastIndexOf('/') + 1;
int removeLenght = words[i].Substring(barIndex).Length;
words[i] = Reverse(words[i]);
words[i] = words[i].Remove(barIndex, removeLenght);
words[i] = words[i].Insert(barIndex, Reverse(replacement));
string ToReverse = words[i];
words[i] = Reverse(ToReverse);
break;
}
}
for(int i = 0; i < words.Length; i++)
{
result += words[i] + " ";
}
result = result.Remove(result.Length - 1);
return result;
}
public string Reverse(string s)
{
char[] charArray = s.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
setter直接从javascript设置颜色:
.attr("class", function() { return d > 10 ? "red_text" : "green_text" });