我想知道如何更改d3 chartplotter的日期时间轴的颜色。
我想要改变的颜色是两个条形之间的棕色和白色背景颜色。
如果我这样做:
它只会改变第一个棕色条上方的东西。
是否可以更改这两个条的颜色?
答案 0 :(得分:1)
奇怪的是,我碰巧试图做同样的事情。事实证明这些颜色在MayorDateTimeLabelProvider.cs
中是硬编码的(我已经注意到下面评论中的行)。如果您正在使用已编译的DLL,则无法更改值。就个人而言,D3是如此不成熟,我保留自己的构建并进行更改以根据需要扩展它(例如在这种情况下!)。
public override UIElement[] CreateLabels(ITicksInfo<DateTime> ticksInfo)
{
object info = ticksInfo.Info;
var ticks = ticksInfo.Ticks;
UIElement[] res = new UIElement[ticks.Length - 1];
int labelsNum = 3;
if (info is DifferenceIn)
{
DifferenceIn diff = (DifferenceIn)info;
DateFormat = GetDateFormat(diff);
}
else if (info is MayorLabelsInfo)
{
MayorLabelsInfo mInfo = (MayorLabelsInfo)info;
DifferenceIn diff = (DifferenceIn)mInfo.Info;
DateFormat = GetDateFormat(diff);
labelsNum = mInfo.MayorLabelsCount + 1;
//DebugVerify.Is(labelsNum < 100);
}
DebugVerify.Is(ticks.Length < 10);
LabelTickInfo<DateTime> tickInfo = new LabelTickInfo<DateTime>();
for (int i = 0; i < ticks.Length - 1; i++)
{
tickInfo.Info = info;
tickInfo.Tick = ticks[i];
string tickText = GetString(tickInfo);
Grid grid = new Grid
{
Background = Brushes.Beige // **** HARD CODED HERE
};
Rectangle rect = new Rectangle
{
Stroke = Brushes.Peru, // **** AND HERE
StrokeThickness = 2
};
Grid.SetColumn(rect, 0);
Grid.SetColumnSpan(rect, labelsNum);
for (int j = 0; j < labelsNum; j++)
{
grid.ColumnDefinitions.Add(new ColumnDefinition());
}
grid.Children.Add(rect);
for (int j = 0; j < labelsNum; j++)
{
var tb = new TextBlock
{
Text = tickText,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, 3, 0, 3)
};
Grid.SetColumn(tb, j);
grid.Children.Add(tb);
}
ApplyCustomView(tickInfo, grid);
res[i] = grid;
}
return res;
}