Real Time Line Chart

In today’s post we are going to build a real time line chart with the following features:

  • 8 data series with 100 points each.
  • Ten times per second we add 10 random points to each series and remove the last ten.
  • Each tenth of the second we update the min and max values of the X-axis.
  • Legend
The final chart

The final chart

Create the series

We create 8 series and add them to the Series collection of the chart:

for (int i = 0; i < 8; i++)
{
     LineSeries series = new LineSeries();
     series.StrokeThickness = 3;
     series.Strokes.Add(RandomStroke);
     series.Fills = series.Strokes;
     series.Title = "Series" + i;
     series.XData = new DoubleCollection();
     series.YData = new DoubleCollection();

     for (int j = 0; j < 100; j++)
     {
        series.XData.Add(j);
        series.YData.Add(10 + 10 * i + random.Next(-5, 5));
      }

     lineChart.Series.Add(series);
 }

Each series is drawn with a random generated stroke:

  private Brush RandomStroke
  {
     get
     {
        byte r = (byte)random.Next(0, 255);
        byte g = (byte)random.Next(0, 255);
        byte b = (byte)random.Next(0, 255);
        return new SolidColorBrush(Color.FromArgb(255, r, g, b));
       }
     }

We must set the Title and Fills properties though we don’t need them for the chart – they are used by the legend. The Y-values of the line points are random numbers between 10 and 90.

The Legend

ChartLegend legend = new ChartLegend();
legend.Series = lineChart.Series;
lineChart.Legends.Add(legend);

Our legend is of type ChartLegend, which means we must set its Series property to the list of ChartSeries that the legend explains. The ChartLegend reads the labels for its items from the Title property of a ChartSeries. It draws the series rectangles with the first brush in ChartSeries.Strokes and fills them with the first brush in ChartSeries.Fills. That’s why it was important to set the Title, Fills and Strokes properties as shown above.

The Axis
The axis shows scale divisions with interval 10. Initially they range from 0 to 100 in 10 intervals.

lineChart.XAxisSettings.MinValue = 0;
lineChart.XAxisSettings.Interval = 10;
lineChart.XAxisSettings.LabelType = LabelType.AutoScale;

Updating Data in Real Time

We create a timer that simulates reading real time data. The timer ticks ten times every second:

timer.Interval = TimeSpan.FromMilliseconds(100);
timer.Tick += new EventHandler(OnTimerTick);

When the timer ticks, we generate ten new values for each of the eight series, add them to each series and remove the last ten values:

foreach (LineSeries series in lineChart.Series)
{
    for (int i = 10 - 1; i >= 0; i--)
    {
         series.XData.Remove(series.XData[i]);
         series.YData.Remove(series.YData[i]);
    }
}

foreach (LineSeries series in lineChart.Series)
{
    int counter = 0;
    for (int i = 0; i < 10; i++)
    {
         series.XData.Add(i + maxX);
         series.YData.Add(10 + counter * 10 + random.Next(-5, 5));
     }
     counter++;
}

Here we use a global variable maxX, which we have declared in the class:

private int maxX = 100;

We increase our global variable with 10 to keep up with the change in the data:

maxX += 10;

Updating the Axis
At each tick of the timer we increase the start of the axis with 10:

lineChart.XAxisSettings.MinValue += 10;

Performance Optimization
Performance is greatly improved if we set the thickness of the lines to 1 rather than 3. The reason for this is that Windows GDI system draws thick lines by filling polygons. This requires numerous calculations about the coordinates of each polygon. When the thickness is small, Windows GDI draws lines rather than polygons, which speeds up drawing and performance.

series.StrokeThickness = 3;

Download of the Sample
You can download the sample with complete source code from here:

Download the Sample

MindFusion.Scheduling Pack R1.2013

MindFusion has just released a new version of its Scheduling Pack. Here are details about the new features in the components that are included in the pack:

Visual Studio 2012 support

MindFusion.Scheduling Pack R1.2013 supports Visual Studio 2012. The installer can create VS2012 toolbox palette for the components, and can optionally install VS2012 sample projects. In addition, toolbox palettes are now created for all .NET target frameworks supported by the respective Visual Studio versions.

ASP-Net-16x16MindFusion.Scheduling for ASP.NET

  • Interactive resize of items in all views.
  • Some of the CSS classes have been renamed to provide better consistency across themes. Check the updated CSS Classes topic for details.
  • The bundled jQuery version has been upgraded to 1.9.
A sample monthly schedule.

A sample monthly schedule.

NET-WinForms-16x16MindFusion.Scheduling for WinForms

Exporting
You can now export calendars to PDF files with the new PdfExporter.

Improved Custom Drawing
Items, including their shadows, can now be completely custom-drawn through the new ItemDrawing event. The
ItemDrawing event is raised before the item is rendered by the system and can be used to prevent the default item rendering. Two new events added to the Calendar class signal the start and end of the item drawing phase respectively – BeginItemDrawing and EndItemDrawing.

Miscellaneous

  • All resource collections now implement IList where T is the type of resources in the collection.
  • The GetExactDateAt method works more consistently in various scenarios.
  • Custom texts and icons can be supplied to the Print Preview form of the scheduling reports.
  • All texts within the calendar can be customized explicitly through the new CustomizeText event of the Calendar class.

WPF-16x16Silverlight-16x16MindFusion.Scheduling for Silverlight / WPF

Improved item presenter
The ItemPresenter class now provides the start and end time of the represented item fragment through the new StartTime and EndTime properties. In addition, derived classes can override the new OnStartTimeChanged, OnEndTimeChanged, and OnItemPropertyChanged methods to get notified when the StartTime or EndTime properties change or when any property of the underlying item changes.

Item recurrence

Item recurrence

Improved recurrence
The Recurrence class exposes a new event – ValidateOccurrence, which can be used to validate and customize the occurrences of a recurrence pattern.

MindFusion Pack for ASP.NET R1.2013

MindFusion.ASP.NET Pack R1.2013 has just been released. We have added styles and themes to the Diagramming tool, interactive resize of items in the scheduling control, numerous UI components and more. Here are the details:

diagram16x16Diagramming for WebForms

Styles and themes

You can modify now the appearance of a diagram through styles. Each style is a collection of properties, which can be applied to a given diagram item or to all items of a given type.

A Theme is a collection of styles. Each style in the theme is associated with the diagram items of a specific type and affects all items of this type. Themes can be saved and loaded to / from XML files. You can create custom themes using the Theme Editor tool.

The Slate Theme

The Slate Theme

Node effects

Nodes support two visual effects – a GlassEffect and an AeroEffect. To apply an effect, you should create an instance of the respective class, set its properties and add the instance to the Effects collection of the node. Effects can be added, removed or modified at any time and this will reflect immediately on the diagram.

One-way graph layout

The OneWayLayout class ensures that links enter into nodes from the same general direction and exit them from the opposite side. If the graph contains cycles, some links bend around the nodes to keep the enter/exit direction consistent. The algorithm aims to minimize the number of such links.

One Way Layout

One Way Layout

Multiple labels per link

The LinkLabel class lets you display multiple captions for a single DiagramLink object. Link labels have a variety of properties for full customization of their display and positioning.

Layers

Diagram items can be assigned now in layers and layers can be hidden, locked, moved up/down in the Z-order as a group. Use the LayerIndex property of items to associate them with a given layer in the Diagram.Layers collection.

Traffic map drawn with MindFusion.Diagramming for ASP.NET

Traffic map drawn with MindFusion.Diagramming for ASP.NET

Parallel layouts

The .NET 4 version of NetDiagram takes advantage of the Task Parallel Library (TPL) to enable parallelism on the different layout algorithms. Set the EnableParallelism property on the Layout class to true to enable arranging different subgraphs on different threads to possibly improve performance on multiprocessor systems.

Magnifier tool

The new magnifier tool allows users to interactively zoom in (or out) portions of the diagram by holding down a modifier key or pressing a mouse button. The magnifier’s zoom factor and appearance can be customized.

The Magnifier Tool

The Magnifier Tool

Miscellaneous

  • Automatic postback mode
  • Enhancements in Canvas mode
  • Enhancements in ImageMap mode
  • The value of the DiagramItem.ZIndex property is no longer required to be unique and
    smaller than the number of items
  • and many more.

Calendar-16x16Scheduling for WebForms

  • Interactive resize of items is now available in all views.
  • Some of the CSS classes have been renamed to provide better consistency across themes.
  • The bundled jQuery version has been upgraded to 1.9.
MonthRange view

MonthRange view

uiMindFusion.UI for WebForms

The following new components have been added to MindFusion.UI for WebForms:

  • Button – a customizable control, which can act as a regular HTML button, Link or
    ImageButton;
  • CheckBox – a customizable control, which can act as a two- or three state checkbox or
    Radio button;
  • DropDown – a drop-down list control that supports binding;
  • MaskTextBox – represents a text input control that constrains the user input to a
    specified mask;
  • PasswordBox – represents a text input control with password protection;
  • Slideshow – provides the ability to display a set of images as a slideshow;
  • TextBox – represents a customizable text input control;
  • Zoom – represents an image zoom tool.
Data input form

Data input form

You can read more about the new features of the components in the ASP.NET Pack at the forum. The new version is available for download from this link:

Download MindFusion Pack for WebForms R1.2013

About MindFusion.WinForms Pack: A set of WebForms components that add great variety of features to your ASP.NET application with a few mouse clicks. The pack contains advanced components for diagramming, scheduling, charting and UI (Accordion, ColorPicker, TabControl, Window, WindowHost, DockControl, Button, Slideshow, Zoom and more). Each tool boasts easy to learn and use API and is quickly integrated into any web application that targets the ASP.NET platform. The controls support numerous options for styling, data import / export, user interaction and offer rich event set. There are plenty of samples and step-by-step tutorials as well detailed documentation.

Use the features page for each of the tools to find out more about its capabilities and
the numerous ways it can boost your performance and speed up the development of your application:

Visit the buy page for details on the licensing scheme and prices. If you have questions please contact us. We shall be happy to assist you.

Diagramming for Java Swing 4.0.1

MindFusion has released a new version of its Diagramming component for Java Swing with various new appearance and layout features. Here are the details:

Preserve order in tree layout

The new Balance property can be set to Preserve to keep the original geometric order of child nodes when arranging them under their parent. This can be used to arrange tree branches in a specific order by first placing them in increasing horizontal or vertical positions.

The tree layout algorithm

The tree layout algorithm

Undirected Path Finding

PathFinder supports undirected mode. Its methods have been changed from static to instance, and its constructor takes an ignoreDirection parameter. If ignoreDirection is enabled, the underlying graph is treated as undirected and link direction is not considered when looking for paths.

Detecting a cycle in a graph.

Detecting a cycle in a graph.

Selection Improvements

Miscellaneous

  • Style classes now contain a FontUnit property specifying the unit of measure of FontSize.
  • The last row in a TableNode will now be rendered clipped if it fits only partially inside the node, whereas in previous versions the row would not be rendered at all.
  • The AllowAddChildren and AllowRemoveChildren properties of ContainerNode specify whether users are allowed to add or remove child nodes to / from the container.
  • and many more.

You can learn more about the new JDiagram 4.0.1 at the news page on MindFusion’s forum. You can download the trial version of the control from the link below:

Download MindFusion.Diagramming for Java Swing 4.0.1

Technical support

Your questions about the diagramming library or any other of our components are welcomed by our support team. You can write at the forum, help desk or at support@mindfusion.dev.

About Diagramming for Java Swing: JDiagram provides your Java Swing application with all necessary functionality to create and customize a diagram. The library is very easy to integrate and program. There are numerous utility methods, rich event set, more than 80 predefined shapes. The tool supports a variety of ways to render or export the diagram, advanced node types like TreeView nodes, hierarchical nodes, tables, container nodes and many more. There are 15 automatic layouts, various input / output options and fully customizable appearance. A detailed list with JDiagram’s features is uploaded here. You can check the online demo to see some of the functionality implemented.

JDiagram is royalty free, there are no distribution fees. Licenses depend on the count of developers using the tool – check here the prices.

Scheduling for ASP.NET 3.1

We have released version 3.1 of MindFusion.Scheduling for ASP.NET. The new features include:

  • items can be resized interactively in all views
  • Visual Studio 2012 support
  • some CSS classes have been renamed to provide better consistency across themes. Check the updated CSS Classes help topic for details.
  • the bundled jQuery version has been upgraded to 1.9

webplanner

Registered customers with an active upgrade subscription can download the licensed version from the clients area on our site.

A trial version is available for download from this link:

Download MindFusion.Scheduling for ASP.NET 3.1

Technical support

MindFusion takes pride in providing excellent customer support to all its clients and evaluators. You can contact us per e-mail support@mindfusion.dev, at the forum or the help desk. We’ll be happy to assist you.

About MindFusion.Scheduling for ASP.NET: A programming tool suitable for creating any type of calendar, schedule, time table, resource table and more. The control supports 5 data views that are easy to change; rich event set and user interaction model. Users can create items interactively, define recurring events, or define custom-typed events, scroll the view or use drag&drop to modify an item.

The control provides programmatic access to all schedule objects. The appearance is completely customizable, built-in themes are also available. At run-time, appointments are created and edited with the built-in form. Every feature is documented in details, there are many tutorials and samples, which provide plenty of code to copy and study. You can learn more about Scheduling for ASP.NET here.