# Chart cubic interpolation

**URL:** <https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870>\
**Category:** Ignition\
**Tags:** ignition80, vision\
**Created:** [June 22, 2020, 12:47pm UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870 "2020-06-22T12:47:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakned](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jakned](https://forum.inductiveautomation.com/u/jakned)\
**Post date:** [June 22, 2020, 12:47pm UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/1 "2020-06-22T12:47:52Z")

</div>

Hi, I took an example from following site:

[https://www.chartjs.org/samples/latest/charts/line/interpolation-modes.html](https://www.chartjs.org/samples/latest/charts/line/interpolation-modes.html)

and I wonder if chart component offers similar functionality. I have a simple chart with one value and I would like to make it more pleasant to an eye by having the line smoothly drawn. For example, in the picture below, I have a green line and i want it to be drawn like the red line.

 ![chart_example](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/e/bebfec45a6a0626f0e5993b6ff7d6ed8304b963c.png)

Thanks for any advice

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [June 22, 2020, 1:29pm UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/2 "2020-06-22T13:29:55Z")

</div>

You can add XYSplineRenderer even though it isn’t in the list of renderer under Dataset Customizer.

I would do something as below:

```auto
from org.jfree.chart.renderer.xy import XYSplineRenderer

chart = event.source.chart
plot = chart.getXYPlot()

renderer = XYSplineRenderer()

# The Precision makes curve smooth ! You can play with changing the numbers.

renderer.setPrecision(15)

plot.setRenderer(renderer)

```

I have this script on the mouseClicked Event Handler of the chart which changes the chart to curve when I click on it. Best Idea would be to have it on ConfigureChart Extended Function !!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/a/fa5a1a004a77b4d97332d77c375074c64069010d.png)

---

<div class="post-metadata">

**Author:** ![jakned](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jakned](https://forum.inductiveautomation.com/u/jakned)\
**Post date:** [June 23, 2020, 7:53pm UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/3 "2020-06-23T19:53:02Z")

</div>

How would multiple datasets or pens change the code? Thank you!

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [June 23, 2020, 8:25pm UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/4 "2020-06-23T20:25:12Z")

</div>

If you’re adding a new series (dataset), code won’t change as long it’s the same plot because you’re rendering to the plot which includes all series.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/6/46638a0cfc04a20bc9a6f4614743dc187126babf.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/c/5c261243b4b8e1fbd649dbc97e473bffcee95088.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/f/bf79fa7904518fd3ea3bfcb04b3b62741103c0e3.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 23, 2020, 10:08pm UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/5 "2020-06-23T22:08:13Z")

</div>

Oddly, the second dataset wouldn’t correctly render for me. I had to use this:

```python
	from org.jfree.chart.renderer.xy import XYSplineRenderer
	
	plot = chart.getPlot()
	rendererCount = plot.getRendererCount()
	
	renderer = XYSplineRenderer()
	
	# The Precision makes curve smooth ! You can play with changing the numbers.
	
	renderer.setPrecision(15)
	
	for i in range(rendererCount):
		plot.setRenderer(i, renderer)

```

Also this completely breaks if you use subplots, as the plot type goes to CombinedDomainXYPlot.

This seems to work for me:

```python
	from org.jfree.chart.renderer.xy import XYSplineRenderer

	renderer = XYSplineRenderer()
	# The Precision makes curve smooth ! You can play with changing the numbers.
	renderer.setPrecision(15)

	plot = chart.getPlot()
	# Get plot type
	plotType = plot.getPlotType()
	
	if plotType == 'XY Plot': 
		rendererCount = plot.getRendererCount()
		for i in range(rendererCount):
			plot.setRenderer(i, renderer)
	if plotType == 'Combined_Domain_XYPlot':
		subplots = plot.getSubplots()
		for subplot in subplots:
			rendererCount = subplot.getRendererCount()
			for i in range(rendererCount):
				subplot.setRenderer(i, renderer)

```

 ![2020-06-23_18-09-03](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/8/0866f42e05fc59a694b7b3a4446aed3ab0be1b44.png)

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [June 24, 2020, 1:41am UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/6 "2020-06-24T01:41:36Z")

</div>

I was, without a doubt, expecting something like this from you !!  
Got much to learn from you through this forum.  
Thanks

---

<div class="post-metadata">

**Author:** ![jakned](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jakned](https://forum.inductiveautomation.com/u/jakned)\
**Post date:** [June 29, 2020, 11:27am UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/7 "2020-06-29T11:27:20Z")

</div>

Thank you Jordan,  
I have tried your code and it makes all lines smooth as intended.  
Problem is, that all lines are now colored red. See picture below:

 ![all_red](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/d/cda548ef0d68210a97f0e9eb076cfb34b3b31c92.png)  
Without the code the chart looks like this:  
 ![all_orig](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/8/f8ad3684495c7554e72cdf60de6b5b1fe516b478.png)  
How can I set different colors to those lines and also get rid of those shapes attached to them?

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [June 30, 2020, 1:39pm UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/8 "2020-06-30T13:39:03Z")

</div>

```auto
Try this...

from org.jfree.chart.renderer.xy import XYSplineRenderer
from java.awt import Color, Font

chartColors = [Color.BLACK, Color.GREEN, Color.CYAN, Color.orange, Color.GRAY]

renderer = XYSplineRenderer()
`# The Precision makes curve smooth ! You can play with changing the numbers.`
renderer.setPrecision(15)

#This will hide the shapes !
renderer.setBaseShapesVisible(0)
chart = event.source.chart
plot = chart.getPlot()

`# Get plot type`
plotType = plot.getPlotType()

if plotType == 'XY Plot': 
	rendererCount = plot.getRendererCount()
	for i in range(rendererCount):
		plot.setRenderer(i, renderer)
if plotType == 'Combined_Domain_XYPlot':
	subplots = plot.getSubplots()
	for subplot in subplots:
		rendererCount = subplot.getRendererCount()
		for i in range(rendererCount):
			subplot.setRenderer(i, renderer)

#set dynamic Colors - 	
for i in range(plot.getSeriesCount()):
	plot.getRenderer().setSeriesPaint(i, chartColors[i %(len(chartColors))])

```

---

<div class="post-metadata">

**Author:** ![sungkhum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sungkhum/32/10636_2.png) [@sungkhum](https://forum.inductiveautomation.com/u/sungkhum)\
**Post date:** [December 13, 2020, 6:17am UTC](https://forum.inductiveautomation.com/t/chart-cubic-interpolation/35870/9 "2020-12-13T06:17:28Z")

</div>

Anyway to do this in Perspective?
