This is a migrated thread and some comments may be shown as answers.

Initialize datapoints in horizontal axis

3 Answers 128 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 11 Mar 2016, 06:11 PM

I have created a RadCartesianChart that shows live data coming in from a machine in a factory that charts the weight of each unit.

Using this xaml:

<telerik:RadCartesianChart.HorizontalAxis>
    <telerik:CategoricalAxis />
</telerik:RadCartesianChart.HorizontalAxis>

With this code-behind:

RadObservableCollection<double> dbl = new RadObservableCollection<double>();
this.chart.Series[0].ItemsSource = dbl;

Then as data comes in, I add doubles to the dbl variable. This all works well but my horizontal axis starts with no datapoints, therefore no demarcation ticks, and the spread of the first datapoints is ridiculously wide, until it reaches a hundred and then I start removing the zeroeth point and adding the next one at the end. Then it maintains a stable appearance.

I have written a hack by adding 100 datapoints with "0" value like this:

dbl = new RadObservableCollection<double>() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

But I wonder if there isn't a "proper" way to get the desired result.

Bob Graham

 

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 16 Mar 2016, 09:24 AM
Hi Robert,

RadCartesianChart is working with two dimensional data. Passing a collection with one dimensional data - the collection of Double in your case - will work only in a scenario with a categorical axis. Otherwise, no data points will be displayed. In your scenario the chart will automatically create a category for each Double value in the collection. 

When working with categorical data the chart creates categories for each distinct category value in the source collection of the series. Each category slot on the axis has equal width with the other slots. So, for example, if the whole plot area have size 200 pixels and there are 2 categories in the data, the chart will create two categorical slots with 100 pixels width each. If there are 5 categories each slot will be 40 pixels wide. This is why there is a big spread between the data points when you have small number of categories. When you reach 100 items in the collection there will be 100 categories which means 2px for each slot in the scenario with the 200 pixels plot area.

Also, when there is no data in the ItemsSource of the series the chart displays a no data message. In order to avoid this you will need to add some items as you already did.

If your requirement doesn't require categorical scenario you can consider using a scatter series (ex: ScatterLineSeries, ScatterPointSeries, etc.) and another numerical axis (ex: LinearAxis) to display the data. This way you can define the axis range manually and avoid the big spread between the data points. 

Regards,
Martin
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Robert
Top achievements
Rank 1
answered on 16 Mar 2016, 04:44 PM

Yes, I understood most of what  you're saying more or less intuitively. It's not really exact to say this is one-dimensional data, there is a quantity and a time axis (the categorical one), we just don't care about seeing the time between data-points accurately spaced.

I would think that for reading live data where the user is only interested in the quantity (vertical) there could be a data point width value on the horizontal axis in the case where plotting the time between arriving quantity values is not of interest.

But I can work with it as is, I understand that what I'm asking for might require re-wiring at a level deeper than reasonable.

Bob

0
Accepted
Martin Ivanov
Telerik team
answered on 21 Mar 2016, 09:03 AM
Hi Bob,

Thank you for the additional information.

The chart axes understand data and they cannot be adjusted with pixel sizes. So, they are expecting to set their range based on some data. For example, minimum and maximum values or categories. When you pass a collection of doubles to the chart, the categories will be created automatically based on the axis. The CategoricalAxis will create "0", "1", "2", etc. 

As I understand the distance between the data points it is not important and it can be equal. In this case the solution with the dummy data is okay for your scenario. If it doesn't work for you, you can send me a drawing of the expected result so I could think of a more suitable solution if there is such.

Regards,
Martin
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
ChartView
Asked by
Robert
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Robert
Top achievements
Rank 1
Share this question
or