<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Creating a chart with dynamic number of series]]></title><description><![CDATA[<p dir="auto">Heya,</p>
<p dir="auto">I am trying to create a chart with a dynamic (1+) number of series. For example, I may have up to 3 temperature values that I want to chart but if 1-2 of them do not exist, I don't want their series to appear on the chart. I don't want to create multiple charts for each variation as this would be headache to update in the future.</p>
<ol>
<li>I found another post regarding hiding a series but it only seemed to hide the chart line. The legend and axis values were still displayed.</li>
<li>I thought maybe if I set the series values parameter to null it might be ignored. That didn't work.</li>
<li>I tried making a component but discovered that having a dynamic template didn't seem possible. Maybe this is but I haven't figured it out yet.</li>
<li>The closest I came to success was when I created a directive. However, the chart was not displayed but the legend and download button were.</li>
</ol>
<p dir="auto"><img src="https://camo.nodebb.org/18f9faf13519c559727b02f9031b040d606d44a4?url=https%3A%2F%2Fi.imgur.com%2FKztG3oJ.png" alt="0_1581719704497_1c8a178f-cff2-4b32-a08e-af43c57721c2-image.png" class=" img-fluid img-markdown" /></p>
<pre><code>userModule.directive('scaRampChart', ['$compile', function ($compile) {

	var ctrl = this;

	var getChart = function(attrs) {
		console.log('attrs = '+JSON.stringify(attrs));

	return '&lt;ma-serial-chart style="height: 300px; width: 100%"' +
            
	'series-1-values="'+attrs.pcuRamp+'"' + 
	'series-1-title="Transmitter Ramp"' +
	'series-1-color="#256eff"' +
	
	'series-2-values="vPcuActive"' +
	'series-2-title="Transmitter Connected"' +
	'series-2-color="#256eff"' +
	'series-2-axis="right"' +
	'series-2-type="step"' +
	'series-2-graph-options = "{\'dashLength\': 5, \'fillAlphas\': 0.1}"' +

	'legend="true"' +
	'balloon="true"' +
	'export="true"' +
	'default-type="line"' +
	'default-graph-options="{title: \'Comparison\'}"' + 
	'options="{' +
	'	synchronizeGrid: false,' +
	'	valueAxes:[' +
	'		{minimum: \'0\', maximum: \'4500\'},' +
	'		{title: \'Connected\', titleColor: \'#ff4d4d\', minimum: 0, maximum: 1, integersOnly: true, baseValue: 2},' +
	'		{title: \'&amp;deg;C\', titleColor: \'#ff4d4d\', minimum: -50, maximum: 50}' +
	'	]' +
	'}"&gt;' +
	'&lt;/ma-serial-chart&gt;';
	}

    var linker = function($scope, $element, $attrs){
		// console.log('in linker...');
		$element.html(getChart($attrs)).show();
        $compile($element.contents())($scope);
    };

    return {
        restrict: "E",
        replace: true,
        link: linker,
        scope: {
			content:'=',
			pcuRamp: '&lt;?'
        }
    };
}]);
</code></pre>
<p dir="auto">Is there something else that I should consider? Is the directive something I should continue to work on?</p>
<p dir="auto">Can the series be specified using a JSON string instead of the component parameters?</p>
<p dir="auto">Thanks<br />
Ian</p>
]]></description><link>https://forum.mango-os.com/topic/4707/creating-a-chart-with-dynamic-number-of-series</link><generator>RSS for Node</generator><lastBuildDate>Fri, 08 May 2026 12:25:54 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/4707.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Feb 2020 22:23:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Creating a chart with dynamic number of series on Mon, 17 Feb 2020 21:57:19 GMT]]></title><description><![CDATA[<p dir="auto">I did something similar, the easiest way I did it was hard coding three graph series and wrapping it with an <code>ng-if="seriesCount==1"</code> or 2 or 4 in the html template file.<br />
You know for a fact you're working with only up to three series, so it shouldn't be overkill.<br />
Store all necessary settings in your JSON then go forth. I think you're making it more complex than required.</p>
<p dir="auto">Alternatively,<br />
Map everything into controller variables then link them into the chart instance:</p>
<pre><code>&lt;ma-serial-chart points="$ctrl.points" values="$ctrl.values" legend="true"
     export="true" graph-options="$ctrl.graphOptions" options="$ctrl.serialChartOptions"&gt;
&lt;/ma-serial-chart&gt;

&lt;ma-point-values points="$ctrl.points" values="$ctrl.values" from="$ctrl.dateBar.from" to="$ctrl.dateBar.to" rollup="{{$ctrl.rollupType}}"
  rollup-interval="{{$ctrl.rollupInterval}} {{$ctrl.rollupIntervalPeriod}}" &gt;&lt;/ma-point-values&gt;
</code></pre>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/24692</link><guid isPermaLink="true">https://forum.mango-os.com/post/24692</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Mon, 17 Feb 2020 21:57:19 GMT</pubDate></item></channel></rss>