AnyChart
AnyChart copied to clipboard
Error in type defs?
The following code is giving me type errors using the bundled definitions. I'm attempting to assemble a mixed series (column + line) chart with a dashed line.
let usage = anychart.data.set(data['usage']).mapAs({
x: 0,
value: 1
})
let license = anychart.data.set(data['license']).mapAs({
x: 0,
value: 1
})
let chart = anychart.column();
chart.animation(true);
chart.title('Mixed Line / Column chart of usage and license')
chart.column(usage);
let licenseLine = chart.line(license)
licenseLine.name('APM License')
licenseLine.size(4)
licenseLine.stroke({
color: '#6C6C6C',
dash: '3 5 10 5'
})
Everything from licenseLine.size(4) has the red squiggly with the messageProperty size does not exist on type Line.
In this case, the chart.line() constructor returns an anychart.core.cartesian.series.Line which doesn't appear to have a size property.
I had tried method chaining too - but the licenseLine.name('') call returns a anychart.core.SeriesBase which also doesn't expose a size property. Same for stroke.
Is this incorrect, or is there a way I can force an appropriate type here?
@jamesrmccallum Line series doesn't have method size(). I guess that you want to set line thickness. If so, you can do it in the following way:
licenseLine.name('APM License'); licenseLine.stroke({ color: '#6C6C6C', thickness: 4, dash: '3 5 10 5', });
This should work!
Also, you can learn more about this method here - https://api.anychart.com/anychart.core.cartesian.series.Line#stroke
@Shestac92 - thanks for responding so quickly. I was following this example from the gallery maybe that's an older API? Certainly the call to size in my code doesn't seem to do anything.
So i remove the size call, and try to chain the calls as follows:
let licenseLine = chart.line(license)
licenseLine
.name('APM License')
.stroke({
color: '#6C6C6C',
thickness:4,
dash: '3 5 10 5'
})
I still get property stroke does not exist on type SeriesBase because the .name() call returns a SeriesBase. Should the name call here return the self type anychart.core.cartesian.series.Line ?
@jamesrmccallum it seems to be a misprint in the sample code. The size() method is not defined for line series.
We've found out a bug thanks to your report. Due to this bug, you can't set stroke settings as an object, only with a set of arguments or in a callback function. We will provide the fix with the release of 8.2.0 version (March 2018). As a temporary workaround you can adjust line series like this:
var licenseLine = chart.line(license);
licenseLine
.name('APM License')
.stroke('#6C6C6C', 4, '3 5 10 5');
You can check a sample of using it here - https://playground.anychart.com/45pJdrxD Thank you for your report!