Barchart's Bar width & ScrollBar Position

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
Ramajayam
Posts: 11
Joined: Mon Feb 10, 2014 12:21 pm

Barchart's Bar width & ScrollBar Position

Post by Ramajayam » Mon Feb 10, 2014 12:30 pm

Hi,
I'm facing some issues:
1. How to control the width of the bar?
ViewXY.BarViewOptions.Grouping = BarsGrouping.ByIndexFitWidth;
When the number of points in the series are very large, this option leads to very narrow Bar width (even leads to a single very thin line)
If ViewXY.BarViewOptions.Grouping = BarsGrouping.ByIndex or ByLocation, the Bars are getting collided with each other, when the number of points are very large.
So How to control the width of the bar?
I want to keep the same width for all the bars in the graph.

2. How to get the current width of the X-Axis?
If I place the LighningChartUltimate control on my control, it is displaying. But X-Axis width or Divs is adjusted automatically based on the width of the control
This issue may be related to the (1) above issue.

3. Is there any API documentation for this LightningChart?
So that I can refer it to understand each property usage. You have //Comment for each property. But it is not useful.

Can anyone please help?

Thanks

ArctionJari

Re: Barchart's Bar width & ScrollBar Position

Post by ArctionJari » Tue Feb 11, 2014 12:20 pm

Hi.

1. If you want to use every possible space for bars then I suggest that you set BarViewOptions.BarSpacing and BarViewOptions.IndexGroupingFitSideMargins to zero. This way there are no side margins and the space between each bar is removed.

2. I'm not sure if I understood your problem... X axis width is automatically calculated. You can use X axis' CustomTicks and CustomTicksEnabled to create your own ticks or set MajorDiv/MajorDivCount and MinorDiv/MinorDivCount so that tick are the way you want them to be.

3. You can either use Visual Studio's help to read LightningChart Ultimate's class, methdod etc descriptions or open the CHM file in "Documents" folder which is located in where you installed LightningChart Ultimate SDK.

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Barchart's Bar width & ScrollBar Position

Post by ArctionPasi » Tue Feb 11, 2014 12:30 pm

We have also written an useful User's Manual. That is installed in the LightningChart program folder, and a shortcut can be found from Start menu. Direct web link is here: http://www.arction.com/download/lightni ... manual.pdf
LightningChart Support Team, PT

Ramajayam
Posts: 11
Joined: Mon Feb 10, 2014 12:21 pm

Re: Barchart's Bar width & ScrollBar Position

Post by Ramajayam » Wed Feb 12, 2014 3:25 pm

The problem, that I face is the collided bars. Refer the attached image.
I used the BarViewOptions.Grouping = BarsGrouping.ByLocation;
I want the bars separated by some little space i.e. look good and meaningful.
But if the number of points increases, it seems ugly.
I tried the BarSpacing set to 5. But no use. if I use grouping.ByIndex also, facing this kind of issue.
Attachments
collided bars.jpg
collided bars.jpg (29.44 KiB) Viewed 16955 times

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Barchart's Bar width & ScrollBar Position

Post by ArctionPasi » Wed Feb 12, 2014 6:16 pm

The correct way to maximize the bars width to visible area is to set:

ViewXY.BarViewOptions.Grouping = ByIndexFitWidth. //This sets the bars to adjust their width to the width of the chart.
ViewXY.BarViewOptions.IndexGroupingFitSideMargins = 0. //This removes the space from left side of the first bar, and right side of the last bar.
ViewXY.BarViewOptions.IndexGroupingFitGroupDistance = 1. //Minimizes the space between bars.
Little bar chart
Little bar chart
LittleBarsChart.jpg (19.69 KiB) Viewed 16952 times
Note that the bar widths are always calculated as integer values, and you may see a little bit of empty space in the right, depending on the chart size.
LightningChart Support Team, PT

Ramajayam
Posts: 11
Joined: Mon Feb 10, 2014 12:21 pm

Re: Barchart's Bar width & ScrollBar Position

Post by Ramajayam » Thu Feb 13, 2014 4:27 am

I already understand it about Grouping.ByIndex, ByIndexFitWidth.
My case is, if I add more and more points, the bar width is getting very narrow (refer the attached image).
For that only, I'm asking about how to set the width of the Bar?

What I want is, I need a good Bar chart with good meaningful display, with 100 - 500 bars, with Scrolling support.
Attachments
Bar with ByIndexFitWidth.jpg
Bar with ByIndexFitWidth.jpg (14.49 KiB) Viewed 16950 times

ArctionJari

Re: Barchart's Bar width & ScrollBar Position

Post by ArctionJari » Thu Feb 13, 2014 4:00 pm

You can download a demo solution (C#, WPF, Visual Studio 2010) from here: http://www.arction.com/download/MapAndBarsWPF.zip

Bar thickness is calculated from chart's width (10 bars per view) and 500 bars overall. I think this should solve your problem. :) Note that it uses WPF's scrollbar instead of LCU's scrollbar but the idea is the same.

fischertc
Posts: 18
Joined: Wed Feb 12, 2014 6:16 am

Re: Barchart's Bar width & ScrollBar Position

Post by fischertc » Sun Feb 16, 2014 4:04 am

I had the same issue with a bar chart that the user can zoom into and out of. What I did was to get the bar values between min and max for every bar and use the ValueToCoord method to set them, like this:

Code: Select all

// Get data from series which will be displayed. Not that it adds/subtracts from max/min to get the bars just offscreen as they may be partially displayed
var barSeriesData = from n in _chart.ViewXY.BarSeries
                              where n.Values[0].Location >= _chart.ViewXY.XAxes[0].Minimum - .001 && n.Values[0].Location <= _chart.ViewXY.XAxes[0].Maximum + .001
                              select n;
if (barSeriesData != null && barSeriesData.Count() > 0)
{
    double SingleItemWidth = 0.0;
    int resultCount = barSeriesData.Count();

    double coord2 = 0.0;

    // Loop through all the results and calc a barwidth for each using screen coordinates
    for (int i = 0; i < resultCount; i++)
    {
        // Get the current series
        BarSeries series = barSeriesData.ElementAt(i);
                     
       // Get its location and convert it to a screen corrdinate
       double loc = barSeriesData.ElementAt(i).Values[0].Location;
       double coord1 = _chart.ViewXY.XAxes[0].ValueToCoord(loc);

       // Get the next result and convert it to a screen coord
       if (resultCount > i + 1)
       {
           double loc2 = barSeriesData.ElementAt(i + 1).Values[0].Location;
           coord2 = _chart.ViewXY.XAxes[0].ValueToCoord(loc2);
       }

      // Work out the width. The last element will be compared to itself and will be zero so it uses the previous width.
      if (Math.Abs(coord2 - coord1) != 0.0)
      {
           SingleItemWidth = Math.Abs(coord2 - coord1);
      }

      // A series bar centers itself on its location value and this width seems to work ok
      series.BarThickness = (int)(Math.Ceiling(SingleItemWidth)); 
}
Since it converts double to int there is an error factor that creeps in as you zoom way into the bars but it is not so noticable that my users complain. Since it gets offscreen bars I always get at least 3 bars in the results so I have not had any issues with bars disappearing.

Post Reply