简体   繁体   中英

WPF C# DynamicDataDisplay - Changing the DateTimeAxis Color

I'd like to know how could I change the color of the date time axis of my d3 chartplotter.

在此处输入图片说明

The color that I want to change is the brown color and the white background color between the two bars.

If i do that :

It only changes the thing above the first brown bar.

在此处输入图片说明

Is it possible to change the color of these two bars ?

Curiously, I've happened to be trying to do the same thing. It turns out those colours are hard-coded in MayorDateTimeLabelProvider.cs (I've noted the lines in comments below). If you're using the compiled DLL then there is no way to change the values. Personally, D3 is so immature that I keep my own build of it and make changes to extend it as needed (such as in this case!).

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM