This tutorial teaches you how to create and customize a graph in Microsoft Excel. This is the third of a four-part tutorial on creating professional reports in Microsoft Excel using LabVIEW and the LabVIEW Report Generation Toolkit, which is included with LabVIEW Professional 2014 and later.The first and second parts of the tutorial teach you how to open Excel, add data to a worksheet, and manipulate that data in Excel using the toolkit. The third part of the tutorial builds on that work to create and customize graphs for better data presentation.
In Figure 1, the Lesson 2 VI represents the code developed in the first and second parts of this tutorial, which teach you how to open Excel, add and rename worksheets, add data to a worksheet, and manipulate that data with functions and macros.
Figure 1. Retrieving Data from an Excel WorksheetBefore you can create a graph, you need to have the data values in one array within LabVIEW. Because you added data at two different points in the VI, the easiest way to gather those values into one array is to read them back from the Excel worksheet. Use the Excel Get Data VI to retrieve the data from the worksheet to LabVIEW. This VI reads a large data set after you specify a cell range and expected data type.
After retrieving the data, create a graph on the worksheet. Excel contains several default graph types you can use to portray the data. In this case, select a line graph with marker points embedded as an object in the worksheet to plot the sample data. Alternatively, you can use the toolkit to create graphs as objects not embedded in a worksheet if you only need to present data visually without accompanying text. As shown in Figure 2, you can use the Excel Easy Graph VI to create a graph of any valid Excel data type and to specify a title and position.
Figure 2. Creating a Graph on an Excel WorksheetFigure 3 shows the effect of adding the graph through LabVIEW.
Figure 3. Graph Added to a Report in an Excel Worksheet
If you want to customize a graph beyond the options offered in the Excel Chart Wizard, the toolkit includes a full suite of VIs you can use to modify and customize graphs. Figure 4 shows the Excel Set Graph Colors, Set Graph Font, and Set Graph Scale VIs, which adjust the properties of a graph programmatically from LabVIEW.
Figure 4. Customizing the Marker Style, Fonts and Axis’s of an Excel GraphFigure 5 shows the modified graph included in the final report.
Figure 5. Customized Graph in an Excel WorksheetThese advanced options of the LabVIEW Report Generation Toolkit for Microsoft Office reduce development time and eliminate the need to manually polish the final report.
Download the tutorial VIs. Requires LabVIEW 6.0 or later, the LabVIEW Report Generation Toolkit, and Microsoft Office.
The test data and graph in Figure 3 need a title and minor adjustments to fonts and positioning. The final part of this tutorial teaches you how to adjust and customize cells and add a report title to complete the report for final presentation.
Collaborate with other users in our discussion forums
A valid service agreement may be required, and support options vary by country.