Histogram

edited 4:44PM in FastReport .NET
Which is the best way to create a histogram with FR Net?

For example, I have a list of ages:

10,2
27,3
30,7
80,2

I need a histogram chart, showing for each range of ages the count.
For example: 0-20, 20-40, 40-60, 60-80

I am trying to use directly the chart over the dataset, but I cannot find how to group the ages.
The other option is to pre-process the data using a function, but first, I would like to know if there are some way to automatize it.

Thank you

Comments

  • edited 4:44PM
    Hello,

    The grouping feature of Microsoft Chart control is not working very well in case when you group by number interval, so it's better to prepare the grouped data before passing it to the chart.
  • edited 4:44PM
    Please can you provide a basic guide?

    I am creating a dll with the pre-processing functions. Now, I have several options, I have thought something like:


    var dataset=Distribution.CreateHistogram((Report.GetDataSource("ds") as ViewDataSource).View, "Ages", min, intervals, width);

    Report.RegisterData(dataset, "dsHistogram");
    MSChart1.DataSource = Report.GetDataSource("dsHistogram");


    I was thinking that maybe you can advice me with a best way to do it. Maybe I could create a "dummy" dataset in the editor and fill it from a function, ...

    By the way, Distribution.CreateHistogram is a function that returns a DataView with the distribution registers.

    Thank you
  • edited 4:44PM
    It's better to register that datasource before you run the report. In this case you may set up the chart visually, and don't use a script to fill it. Another option is to use chart.BeforePrint event script:

    MSChart1.Series[0].ClearValues();

    DataView view = Distribution.CreateHistogram((Report.GetDataSource("ds") as ViewDataSource).View, "Ages", min, intervals, width);

    // now enumerate the dataview rows and add values to the chart
    ...
    MSChart1.Series[0].AddValue(x, y);

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.