SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Answered
1
0

Hi,

I’m trying to have constant sized column bars. As far as I know, the only property to change the X size of a bar is to use DataPointWidth which is a float between 0 and 1. It’s stated that it “Gets or sets the DataPointWidth, a value between 0.0 and 1.0 which defines the fraction of available space each column should occupy”.

But if I add two bars in the series, the available space shrinks, causing the bars to look thinner than the other series which only has 1 bar, creating an inconsistent look. It’s not a problem when I have equal number of bars in the series of course.

Is there a way to get around this problem, ideally I would have liked to have the DataPointWidth to accept the amount of X value it should be covering.

I’ve considered using the PalletteProvider with a single series, but it only returns Color, and I want to return Brush (for gradient effect). Also, I don’t want to change the border color. I couldn’t get it to work anyway, I’m probably missing something though,

I’ve set the

 renderer.PalletteProvider = new ProviderImplementation()

But it didn’t even hit the break points, but since I wasn’t interested in solid colors, decided to not pursue that.

Thanks

Edit: I’m using 3.3.0.5736v, I’ve added my PalletteProviderImplementation, I’ts not hitting any of those breakpoints.

Images
  • You must to post comments
Best Answer
3
0

Hi there,

Unfotunately column series doesn’t support this behavior out of the box. But you could easily implement it by overriding GetColumnWidth method:

public class ConstantColumnRenderableSeries : FastColumnRenderableSeries
{
    public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.Register(
        "ColumnWidth", typeof (IComparable), typeof (ConstantColumnRenderableSeries), new PropertyMetadata(default(IComparable), OnInvalidateParentSurface));

    public IComparable ColumnWidth
    {
        get { return (IComparable) GetValue(ColumnWidthProperty); }
        set { SetValue(ColumnWidthProperty, value); }
    }

    protected override double GetColumnWidth(IPointSeries points, IRenderPassData renderPassData)
    {
        ICoordinateCalculator<double> xCoordinateCalculator = renderPassData.XCoordinateCalculator;

        var value = ConvertToDouble(ColumnWidth);

        return xCoordinateCalculator.GetCoordinate(value) - xCoordinateCalculator.GetCoordinate(0);
    }

    private static double ConvertToDouble(IComparable comparable)
    {
        if (comparable == null)
            return 0;

        if (comparable is DateTime)
            return ((DateTime)comparable).Ticks;

        if (comparable is TimeSpan)
            return ((TimeSpan)comparable).Ticks;

        return Convert.ToDouble(comparable, CultureInfo.InvariantCulture);
    }
}

Then you just need to use it instead of FastColumnRenderabeSeries.

Best regards,
Yura.

  • kewur
    exactly what I was looking for, Thank you.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.