IMDTouchKnowledge BaseShop main store

How-to

Building a Pie Chart on a Comfort Panel in TIA Portal

HMI and touchscreens Published 6 min read

Short answer

A TP1200 Comfort project in TIA Portal V17 has no pie chart object, and its scripts cannot draw one. Compute each sector in a local script as 360 degrees times value divided by total, guard the zero-total and invalid-data cases before dividing, then display the result by switching pre-drawn chart images from an integer tag or scaling bar objects to the percentages.

On this page
  1. What the TP1200 Comfort gives you
  2. The numbers behind every sector
  3. Steps from tags to a chart the panel can render
  4. Worked example: sector angles for 1,200, 960 and 240 units in one shift
  5. Image states, bars, or a different target
  6. Questions asked

A TP1200 Comfort in a TIA Portal V17 project has no pie chart object, and a Comfort panel script has no drawing surface. So you do not draw the chart; you compute it. Read the category values as one consistent set, validate them, and calculate each sector as 360 degrees x value / total. Then render the result with the objects the panel does have: pre-drawn chart images selected by an integer tag, or bar objects scaled to the percentages. The script supplies the numbers; the palette supplies the pixels.

What the TP1200 Comfort gives you #

The object set comes from the configured device, not from the engineering version. For the TP1200 Comfort the palette is the classic WinCC Comfort set: bars, trends, IO fields and imported graphics, with no pie chart among them. The release notes for TIA Portal V20 list pie charts among the WinCC screen configuration elements, but that listing does not put the object into this project. The palette is built from the device in the device configuration, and for this panel it contains no chart object.

What the panel does give you is runtime scripting: system functions in function lists, plus local scripts and user-defined functions in VB Script that read values, calculate and write results. Assignments are all a script can do here. There is no canvas, no sector geometry, and no way to create an object while the runtime runs; everything visible on screen was placed at engineering time and downloaded with the project. Commit to that boundary early: the script computes fractions, an existing object displays them.

The numbers behind every sector #

A pie chart is a fraction-of-total display. For category values x1 to xn with total S, each share is xi / S, each percentage is 100 x xi / S, and each sector angle is 360 degrees x xi / S. These are pure rendering relationships; they hold on any display that can draw a sector, which is exactly what this panel cannot do.

Three conditions make the total meaningful: every value nonnegative, every value in the same unit, and every value from the same population and interval. Counts from different shifts, or rates mixed with counts, do not form a whole just because the tags are numeric. If the source values are already percentages, confirm they cover the entire population; scaling an incomplete set up to a full circle changes what the chart claims. Add a legitimate remainder category or state the coverage in the label.

Two states sit ahead of the arithmetic. If S = 0, no category has a share of anything: display a zero-total state and divide nothing. If a value is negative or its quality flag is bad, display an invalid-data state instead of a chart that misrepresents the process. Both checks run before the first division.

Steps from tags to a chart the panel can render #

  1. Take one snapshot. All category values must come from the same scan or the same reporting interval. The clean way is to let the PLC compute the total in one program scan and publish values and total together, so the panel can never assemble a chart from two process states.
  2. Validate before dividing. In the script: quality good, every value at or above zero, and S greater than zero. If any check fails, write the zero-total or invalid-data state tag and exit; no division runs on an empty set.
  3. Compute every sector in one pass. angle = 360 degrees x value / total for each category, plus the percentage if you label the sectors. If you do this math in the PLC instead of the panel, watch integer division: a controller that truncates turns a 5 percent share into 0 unless you multiply before you divide, the trap behind integer division truncation in a Compute instruction.
  4. Render by image states when a small set is enough. Quantize the shares to a fixed step, map each combination to an integer state tag, and let the panel swap the graphic by value. The mechanism is the one covered in Switching HMI Images With an Integer Variable Value.
  5. Render with bar objects when the shares move continuously. Scale each bar's length to its percentage. A row of proportional bars carries the same information as the pie, with no image set to maintain.
  6. Write the labels in the same pass. Percentages and graphic must come from one calculation, or the numbers and the picture will disagree on screen.
  7. Trigger from the process, and keep the chart on the display side. Update on shift end or batch end, not in a fast free-running cycle. The chart consumes process data; it never commands it. Sequencing and protection stay in the controller.

In outline, with illustrative names; yours come from your own tag table:

Dim catA = 0, catB = 0, catC = 0   ' units, one snapshot
Dim total = 0                       ' units
Dim angA = 0, angB = 0, angC = 0    ' degrees
total = catA + catB + catC
If dataBad Or total <= 0 Then
    stateTag = 0                    ' zero-total / invalid image
Else
    angA = 360 * catA / total
    angB = 360 * catB / total
    angC = 360 * catC / total
    stateTag = MapToState(angA, angB, angC)
End If

Tag reads and writes go through the runtime's documented tag interface in the local script editor, and the worked example below is this outline's test.

Worked example: sector angles for 1,200, 960 and 240 units in one shift #

Inputs, a typical case: the three counter values are illustrative readings and your tags supply the real ones. Three end-of-shift counters from the same shift, all quality good: line 1 = 1,200 units, line 2 = 960 units, line 3 = 240 units.

Rule in words: a sector's angle is 360 degrees multiplied by that line's units, divided by the total units of the shift.

Arithmetic:

  • S = 1,200 + 960 + 240 = 2,400 units
  • Line 1: 360 x 1,200 / 2,400 = 432,000 / 2,400 = 180 degrees
  • Line 2: 360 x 960 / 2,400 = 345,600 / 2,400 = 144 degrees
  • Line 3: 360 x 240 / 2,400 = 86,400 / 2,400 = 36 degrees
  • Closure check: 180 + 144 + 36 = 360 degrees
  • Labels: 100 x 1,200 / 2,400 = 50.0 percent, 100 x 960 / 2,400 = 40.0 percent, 100 x 240 / 2,400 = 10.0 percent

Result: shares of 50.0 / 40.0 / 10.0 percent at angles of 180 / 144 / 36 degrees, closing exactly on the full circle.

Decision: 50/40/10 sits exactly on a 10-percentage-point grid, so an image-per-state build covers this shift with the single 50/40/10 graphic. The guard stands at S greater than zero: a shift that ends at 0 units total must show the zero-total state, never a division. The moment a share must be read finer than 10 points, stop growing the image set and drive bar lengths with the percentages instead.

Image states, bars, or a different target #

Image states win when the categories are few and fixed and a coarse step resolves them: the chart is crisp, the script is a mapper, and the state count stays maintainable, though it grows quickly as the step shrinks. Bar objects win when shares move continuously or categories come and go: no asset set, any resolution, at the cost of the pie silhouette. If the pie shape itself is the requirement and the object must be native, the panel is the wrong target. That is a migration to a PC-based runtime whose visualization ships chart objects, and it is decided at the architecture level, not by a setting in the V17 project.

Questions asked

Can the script draw the pie sectors directly on a TP1200 Comfort?

No. Comfort panel local scripts compute values and assign them to tags and object properties that already exist in the downloaded project; there is no canvas or drawing interface, and an object cannot be created while the runtime is running. Every visible sector has to come from an object or graphic placed at engineering time. That is the whole reason this build maps a computed state to pre-drawn images or to bar lengths.

Is it better to compute the percentages in the PLC?

Often yes, and it solves the snapshot problem at the source: one program scan produces the total and every share from the same values, so the panel cannot mix two process states. Watch the arithmetic. In a controller that truncates integer division, multiply by 360 before dividing, or a small sector computes to zero. The panel script then only validates and displays what arrives.

How many pre-rendered images does a three-category chart need?

It is set by the quantization step. With three categories rounded to 10-percentage-point steps, the distinct states are the combinations whose shares sum to 100 percent: 11 x 12 / 2 = 66 images. Halve the step to 5 points and it becomes 21 x 22 / 2 = 231. That growth is why coarse steps, or bar objects, win as soon as fine resolution matters.

Will upgrading the project give the panel a native pie chart object?

No. The V20 documentation lists pie charts among WinCC screen configuration elements, but the palette is determined by the configured device, and the TP1200 Comfort keeps its classic object set; re-opening the project in a newer engineering version does not add objects to this panel. If a native chart object is a hard requirement, the change of runtime target is the decision, not the version number.

Why do my percentage labels total 99 or 101 percent?

Independent rounding. Three equal shares of 33.33 percent each round to 33 and total 99. Allocate with the largest remainder instead: round the first categories and give the last one what is left, 100 - 33 - 33 = 34 percent, so the labels always sum to 100 and can be matched one-to-one with the image states.

Keep reading

  • Troubleshooting

    Why HMI Data Logs Export Bool True as -1

    A Comfort Panel USB data log shows -1 for a true Boolean because the export serializes the all-ones bit pattern as a signed value. Assign the literals 1 and 0 conditionally into a separate numeric tag and log that tag; a direct copy into an Int or UInt keeps the -1. Verify the change in the raw CSV with a text editor.

    HMI and touchscreens

  • How-to

    Verifying HMI Historical Trend Retention Before Committing

    An 8-hour trend sampled every 5 minutes spans 96 intervals — 97 stored points if both endpoints are kept — so the panel needs a historical buffer of at least 97 samples per tag that repopulates the trend after screen changes. Verify the buffer depth, the interval setting, and restoration behavior on the bench before you build the screens.

    HMI and touchscreens

  • Explainer

    Portrait HMI Panel Mounting and Temperature Derating Explained

    No. Portrait mounting does not derate an HMI panel's temperature rating — the vendor's release information for the panels that gained portrait mode states the landscape specifications continue to apply, because rotation in the screen's own plane leaves tilt, convection and dissipation unchanged. The derating that still governs is mounting angle: the 15-inch model's angle table reads the same row in portrait as in landscape.

    HMI and touchscreens