Interrupt a line in Chart.js lines - charts

I've a weird situation in chart.js, see the picture
Basically a dataset with 4 date and 4 numbers. All 4 numbers value are 1 (doesnt matter).
But actually the real data need to show just 2 intervals (1/1/2020 -> 2/2/2020) and (3/4/2021->6/6/2021). Basically without the segment in the middle.
In this case there is no way Chart.js would be able to understand to not drawn that segment, all values are 1 in all 4 different dates.
So the only solution in my mind is to sub divide all the intervals so I can place a NaN in the middle and use something like stepped:true for the line. But with a lot of data I basically double the numbers of dates making the graph more confusing.
So the question is.. Is there any way to specify for given point if it's a start or an end ?
Or maybe there is a better approach instead of a single line dataset?
Thank you.

Just pass 2 datasets:
const labels = Utils.months({count: 7});
const data = {
labels: labels,
datasets: [{
label: 'My First Dataset',
data: [65, 59, 80],
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
},{
label: 'My 2nd Dataset',
data: [null, null, null, 81, 56, 55, 40],
fill: false,
borderColor: 'rgb(75, 40, 192)',
tension: 0.1
}]
};
If You pass objects instead of arrays as data, then you do not even have to pad with nulls

Related

is it possible for syncfusion chart plotband to have a dynamic associatedAxisEnd value?

I want to be able to have a vertical line from the x-axis to the height of the y value, which is dynamic as it is being taken from a database.
example: for the data point 1 Jan, I want to have a plotband associatedAxisEnd of 45 , 2 Jan associatedAxisEnd of 65 etc...
I'm only able to create a constant associatedAxisEnd height currently, is there a way to be able to loop through the chart data and set the associatedAxisEnd height dynamically?
primaryXAxis: CategoryAxis(
axisLine: const AxisLine(width: 3),
majorGridLines: const MajorGridLines(width: 0,
color: Colors.transparent),
plotBands:
<PlotBand>[
PlotBand(
isVisible: true,
isRepeatable: true,
repeatEvery: 2,
size: 1,
borderWidth: 1,
repeatUntil: 6,
associatedAxisEnd: 50, // is it possible to have a loop on this line?
borderColor: Colors.grey,
dashArray : const <double>[5, 5]
),
]
)
You cannot have a loop when setting values for the PlotBand’s associatedAxisEnd property. However, you can achieve your requirement by adding individual plot band lines for the chart data points as per required.
We have created a simple sample in which we have added plot band lines for the chart data points by lopping through the chart data and attached the sample below for reference. Also appended the user guide documentation link for plot line rendering below for reference.
https://help.syncfusion.com/flutter/cartesian-charts/axis-customization#plot-line
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/i404038-1323531402

Highcharts Pyramid - same size of segments - despite the data value

I was wondering if it would be possible to ignore the sizes of segments in highcharts pyramid. I would like all segments to be of the same size despite the value. The reason is that sometimes differences between values may be quite significant and value of 1 - even being extremely important, becomes invisible when the next value is 500. Also, would like to be able to add a legend if possible. It would be nice to set a minimum size of a segment if not possible to get dynamic sizing disabled.
Thanks for your help!
Pawel
Yes, you can add additional data according to which the height of the segment will be calculated. Next, use keys option to map the values and show the right one in a tooltip and data label:
tooltip: {
pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.realY}</b><br/>'
},
series: [{
...
keys: ['name', 'realY', 'y'],
dataLabels: {
format: '<b>{point.name}</b> ({point.realY:,.0f})',
...
},
data: [
['Website visits', 15654, 1],
['Downloads', 4064, 1],
['Requested price list', 1987, 1],
['Invoice sent', 976, 1],
['Finalized', 846, 1]
]
}]
Live demo: https://jsfiddle.net/BlackLabel/e83fatk2/
API Reference: https://api.highcharts.com/highcharts/series.column.keys

Changing icon offset based on zoom level

I am trying to offset symbols of a symbol layer so that they don't interfere with a previous symbol layer (i.e. they don't overlap). I need to offset them as in both cases icon-allow-overlap needs to be set to true, as the symbols need to be viewable at all zoom levels. Ideally I'd like to do something like this:
"icon-offset": [
["zoom"],
12, [-16, 0],
22, [0, 0]
]
but that gives me an error:
array length 2 expected, length 5 found
Is there a way I can do what I want similar to what I was trying above? I know that icon-offset is not transitionable so that is why the above is failing.
Any help would be appreciated.
Thanks for your time.
The answer was to use a function:
"icon-offset": {
"stops": [
[12, [-16, 0]],
[22, [0, 0]]
]
}
More info on this can be found here

How can I split colors of the area under line chart after a certain threshold (beyond x-axis)

I'm using Baidu's echarts library
How can I split colors of the area under a line chart after a certain threshold (beyond x-axis) using the areastyle?
Thank you!
You can't.
The areastyle is applied to the series itself, and cannot be tied to individual datapoints. Because the area color actually marks the area between two datapoints.
But.., you can, however, create a workaround and create two linecharts, like so:
legend: {
data: ['myLine']
},
series : [
{
name: 'myLine',
type: 'line',
areaStyle: {
normal: {
color: 'red'
}
},
data: [400, 300, 101, 134, null, null, null]
},
{
name: 'myLine',
type: 'line',
areaStyle: {
normal: {
color: 'green'
}
},
data: [null, null, null, 134, 90, 230, 210]
},
]
By adding it manually to the legend, and by giving both series the same name. ECharts combines the two series to some degree, so both the legend and the animation are acting like it's a single series.
Also, make sure to connect the two lines, by adding a datapoint twice (see 134). And you can customize the lines a little more with lineStyle, etc, to make them look better.
You can create a little demo by checking the ECharts demo gallery and replace the series and legend data with the snippet above (you may have to click the blue run button).

Assign a color to individual row numbers

I am trying to assign an individual color to each row in a group. There are approximately 50 rows I need to assign a color and they all must be unique. What would be the easiest way to do this?
I do not want to do the alternating row colors:
"=IIf(RowNumber("DataSet1") Mod 2 = 1, "White","Blue")",
but if there was a way to modify this expression to do 50 colors and then repeat I'd be okay with that.
you can use choose . otherwise use custom code function
=Choose(ROWNUMBER(nothing) mod 50, "Brown", "Blue", "GoldenRod", "Olive", "MediumTurquoise","Red", "Green", "DeepSkyBlue", "Yellow", "Chocolate", "Purple", "DarkOrange" ,.....)