# Chart Class with Custom Property Display

This example shows how to define a class of charts with a custom property display that lists only a subset of the properties. The following code demonstrates how to overload the `getPropertyGroups` method of the `matlab.mixin.CustomDisplay` class. The example also demonstrates the basic coding pattern for charts that derive from the `matlab.graphics.chartcontainer.ChartContainer` base class. You can use this example to become familiar with the coding techniques of chart development, or as the basis for a class you plan to develop.

To define the class, copy the following code into the editor and save it with the name `SmoothPlotCustomDisplay.m` in a writable folder.

```classdef SmoothPlotCustomDisplay < matlab.graphics.chartcontainer.ChartContainer % c = SmoothPlotCustomDisplay('XData',X,'YData',Y,Name,Value,...) % plots a dotted line of the coordinates in X and Y with a smoothed % version of the line. You can also specify additonal name-value % arguments, such as 'SmoothColor' and 'SmoothWidth'. properties XData (1,:) double = NaN YData (1,:) double = NaN SmoothColor {validatecolor} = [0.9290 0.6940 0.1250] SmoothWidth (1,1) double = 2 end properties(Access = private,Transient,NonCopyable) OriginalLine (1,1) matlab.graphics.chart.primitive.Line SmoothLine (1,1) matlab.graphics.chart.primitive.Line end methods(Access = protected) function setup(obj) % Get the axes ax = getAxes(obj); % Create the original and smooth lines obj.OriginalLine = plot(ax,NaN,NaN,'LineStyle',':'); hold(ax,'on') obj.SmoothLine = plot(ax,NaN,NaN,'LineStyle','-',... 'Color',[0.9290 0.6940 0.1250],'LineWidth',2); hold(ax,'off') end function update(obj) % Update line data obj.OriginalLine.XData = obj.XData; obj.OriginalLine.YData = obj.YData; obj.SmoothLine.XData = obj.XData; obj.SmoothLine.YData = createSmoothData(obj); % Update line color and width obj.SmoothLine.Color = obj.SmoothColor; obj.SmoothLine.LineWidth = obj.SmoothWidth; end function propgrp = getPropertyGroups(obj) if ~isscalar(obj) % List for array of objects propgrp = getPropertyGroups@matlab.mixin.CustomDisplay(obj); else % List for scalar object propList = {'SmoothColor','XData','YData'}; propgrp = matlab.mixin.util.PropertyGroup(propList); end end function sm = createSmoothData(obj) % Calculate smoothed data v = ones(1,10)*0.1; sm = conv(obj.YData,v,'same'); end end end ```

After saving the class file, you can create an instance of the chart. Omit the semicolon when you create the chart to see the customized display.

```x = 1:1:100; y = 10*sin(x/15)+8*sin(10*x+0.5); c = SmoothPlotCustomDisplay('XData',x,'YData',y) ```
```c = SmoothPlotCustomDisplay with properties: SmoothColor: [0.9290 0.6940 0.1250] XData: [1x100 double] YData: [1x100 double] Use GET to show all properties ```
{"ft_lang_label":"__label__en","ft_lang_prob":0.53286505,"math_prob":0.9509053,"size":2735,"snap":"2021-31-2021-39","text_gpt3_token_len":704,"char_repetition_ratio":0.12705968,"word_repetition_ratio":0.0,"special_character_ratio":0.25776964,"punctuation_ratio":0.23956443,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9787718,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-30T02:11:42Z\",\"WARC-Record-ID\":\"<urn:uuid:6ea5014e-05c5-4482-9a90-099ed9a68222>\",\"Content-Length\":\"71699\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9556962a-9493-4a23-9eb8-80f73e64c75b>\",\"WARC-Concurrent-To\":\"<urn:uuid:680b3a72-360b-423d-a5ec-cbbf1803ae00>\",\"WARC-IP-Address\":\"23.13.150.165\",\"WARC-Target-URI\":\"https://ch.mathworks.com/help/matlab/creating_plots/chart-class-with-custom-property-display.html\",\"WARC-Payload-Digest\":\"sha1:X5TRMXB3TAFNGY25T5XP4CCXUJ3B5IIK\",\"WARC-Block-Digest\":\"sha1:UIUTX3OJJTAH3UCO6D5I33GSTMIEO5AP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153899.14_warc_CC-MAIN-20210729234313-20210730024313-00626.warc.gz\"}"}