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!

0
0

Hi,

I have a column chart with sparse data. There are about 3000 points (dollar and cent values, i.e. $40.04) spread out over $13900.

I would like to be able to set the columns to take up as much width as possible, but to never encroach on the space in any adjacent points.

For example, if I have a column at $40.04, I would like the column to be drawn in the area stretching from 40.035 -> 40.045 at maximum, so that any possible columns around it (i.e. possible values at 40.03 and 40.05) are never obscured.

Obviously when the chart is zoomed out to maximum limits, the columns will have basically no width, but thats acceptable, as long as when the user zooms in they get some width.

I’ve tried various permutations of the DataPointWidth property, and the only one that is usable is 0, which means the columns never get thicker, even as I zoom in and out (which is not ideal).

Is there any way to do what I want?

  • You must to post comments
0
0

Hello Todd,

Yes you can do this using the FastColumnRenderableSeries.DataPointWidth property. Set to 0.0 to have zero width, and 1.0 to have full width (use all available space for data-point). There is a demo of this feature in the Silverlight Examples Suite

Note in our internal build we have fixed a related bug where DataPointWidth=1.0 leaves a 1 pixel gap between columns as you zoom.

In order to get the width changing, you will need to handle the XAxis.VisibleRangeChanged event and update the DataPointWidth as you zoom. If you want, you can create a custom ChartModifier to do this. Try inheriting from ChartModifierBase and handling events in there.

// Please Note, I haven't compiled this code, but hopefully
// should serve as an example. 
public class ColumnSeriesModifier : ChartModifierBase
{
    public override void OnAttached()
    {
        base.OnAttached();
        this.XAxis.VisibleRangeChanged += OnXVisibleRangeChanged;
    }

    public override void OnDetached()
    {
        base.OnAttached();
        this.XAxis.VisibleRangeChanged -= OnXVisibleRangeChanged;
    }

    private void OnXVisibleRangeChanged(object sender, EventArgs e)
    {
        // delta between minimum and maximum as a double. 
        // If your XAxis is DateTime or CategoryDateTime, this 
        // will return the number of Ticks between Min and Max
        double rangeDiff = XAxis.VisibleRange.AsDoubleRange().Diff;
       
        // Get series off ParentSurface. TODO null checks
        var columnSeries = ParentSurface.RenderableSeries.OfType<FastColumnRenderableSeries>();
    
        // Compute datapoint width based on zoom 
        double dpWidth = CalculateDataPointWidth(rangeDiff);

        // Update. Should trigger a redraw. If not 
        // call ParentSurface.InvalidateParent();
        foreach(var cs in columnSeries)
        {
            cs.DataPointWidth = dpWidth;
        }
    }

    private double CalculateDataPointWidth(double rangeDiff)
    {
        // Need to define a maximum range to have DPWidth=1.0
        // and scale linearly as you zoom 
        const double maxDiff = 10.0;
        return Math.Max(Math.Min(rangeDiff/maxDiff, 1.0), 0.0);
    } 
}

Hope this helps!
Andrew

  • Andrew
    PS: Internally the column series has two modes. When there are more columns than pixels, it automatically draws all columns as 1pixel lines. As you zoom so that there are less columns than pixels, it starts using DataPointWidth.FastColumnRenderableSeries.DataPointWidth means "of the available space for this column, use x% of it, where 0 = 0% and 1.0 = 100%".It is a fixed constant (not zoom dependent) and default value is 0.4, so if you want to vary it as you zoom, ignoring the completely zoomed out case which is automatic, you may need to do it in the VisibleRangeChanged handler.
  • Todd
    Thanks for the reply.How exactly does the chart decide what the available space for the column is?Thats where I'm running into issues, as my columns are sparse, but I want to limit the "available" space to the pixels allocated to $0.01 on the chart, based on the current zoom level.Its almost like I want an axis type of dollars rather than double, as I know the minimum resolution of my data points.
  • You must to post comments
0
0

Hi Todd,

There is piece of code, which calculates width of column(lastPoint and firstPoint are first and last data points of current XAxis.VisibleRange, and points.Count gets amount of data points in this range):

double width = xCoordinateCalculator.GetCoordinate(lastPoint.X)
                           - xCoordinateCalculator.GetCoordinate(firstPoint.X);

int columnPixelWidth = (int)((Math.Abs(width) / points.Count) * dataPointWidth);

Hope this helps!

Best regards,
Yuriy

  • Todd
    That explains everything.Is there a way to override the behaviour that determines the actual pixel size of the columns?I understand it works great when the column series has regularly spaced points, but it gives some very strange results when the column series is sparse (columns change width strangely as you zoom/pan).Its a simple thing to fix if that behaviour can be overriden (simply refer to some known property of minimum axis increment, like 0.01 for my dollar axis, calculate the maximum width using the coordinate calculator, cap the size of the columns to this value).
  • Andrew
    Hi Todd,Hmm, it's not possible to modify the width calculation without tweaking the source code. The class in question is FastColumnRenderableSeries. Do you have access to the source?In any case I will log this as a bug for investigation on our v2.0 branch. We're making some significant changes to coordinate calculation so its worth us addressing them here rather than try to fix in v1.5.Other than that are you getting on ok? Any screenshots you have for strange column sizing please send them over, so I can attach to the bug report.Best regards, Andrew
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.