2

我想知道如何更改 d3 海图仪的日期时间轴的颜色。

在此处输入图像描述

我要更改的颜色是两个条之间的棕色和白色背景色。

如果我这样做:

它只会改变第一个棕色条上方的东西。

在此处输入图像描述

是否可以更改这两个条的颜色?

4

1 回答 1

2

奇怪的是,我碰巧也在尝试做同样的事情。事实证明,这些颜色是硬编码的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;
}
于 2013-11-07T16:25:20.597 回答