How to add a class/id for particular node - raphael

I am using Adrai's flowchart. And I want to change different style of all nodes.
For layout I am using raphael.js.
Can anyone suggest me how could I achieve this.
Here is my code
<script>
window.onload = function () {
var diagram = flowchart.parse('st=>start: Start:>http://www.google.com[blank]\n' +
'e=>end:>http://www.google.com\n' +
'op1=>operation: My Operation1\n' +
'sub1=>subroutine: My Subroutine1\n' +
'cond1=>condition: Yes \n' +
'or No 1?\n:>http://www.google.com\n' +
'op2=>operation: My Operation2\n' +
'op3=>operation: My Operation3\n' +
'sub2=>subroutine: My Subroutine2\n' +
'cond2=>condition: Yes \n' +
'or No 2?\n:>http://www.google.com\n' +
'io=>inputoutput: catch something...\n' +
'' +
'st->op1->cond1\n' +
'cond1(yes, right)->io->e\n' +
'cond1(no)->op2->cond2\n' +
'cond2(yes, right)->io->e\n' + // conditions can also be redirected like cond(yes, bottom) or cond(yes, right)
'cond2(no)->op2');
diagram.drawSVG('diagram');
// you can also try to pass options:
diagram.drawSVG('diagram', {
'line-width': 3,
'line-length': 50,
'text-margin': 10,
'font-size': 14,
'font-color': 'black',
'line-color': 'black',
'element-color': 'black',
'fill': 'white',
'yes-text': 'yes',
'no-text': 'no',
'arrow-end': 'block'
});
};
</script>
Html
<div id="diagram">Diagram will be placed here</div>
For Ex.
This is my output and I want different design style for all nodes like start/condition/operation/end
Any help would appreciated.

May be a little late, but if I refer to the example provided on github (here: https://github.com/adrai/flowchart.js/blob/master/example/index.html ) you can set styles for different symbol types like this (extract from example)
chart.drawSVG('canvas', {
'line-width': 3,
'line-length': 50,
'text-margin': 10,
'font-size': 14,
'font-color': 'black',
'line-color': 'black',
'element-color': 'black',
'fill': 'white',
'yes-text': 'yes',
'no-text': 'no',
'arrow-end': 'block',
'symbols': {
'start': {
'font-color': 'red',
'element-color': 'green',
'fill': 'yellow'
}
}
Here the symbol 'start' is filled in yellow, text in red etc... I suppose you can add whatever style you want on other symbols (stop, op1, etc...).
Looking deeper in the code (https://github.com/adrai/flowchart.js/commit/8fddc7c8bf2a129f2fe9c4288b70218723d141c2) you can see the availables symbols are :
'start',
'end',
'condition',
'inputoutput',
'operation',
'subroutine'
Hope this helps a bit
Cheers

Notice this is only possible for symbol types.
It could be a lot more flexible if it could provide styles for specific IDs

Related

Howto show absolute number in Apexcharts pie chart

The pie chart I created with Apexcharts shows relative (percentage) numbers at the circle (like the "99.9%" in the screenshot below).
Instead of the relative number I'd like to show the absolute value like what's in the tooltip (see example: "6752").
I tried a formatter function with signature function(value, {seriesIndex,dataPointIndex,w}), but value is the relative value (e.g. 99.9), dataPointIndex is undefined, seriesIndex is always 1 and w contains the whole chart config without being specific to this slice of the pie.
How can I show absolute numbers?
You have the right strategy, but probably not the right formatter. The one you need is dataLabels.formatter:
let options = {
series: [10, 20, 15],
chart: {
width: 350,
type: 'pie'
},
labels: ['Label 1', 'Label 2', 'Label 3'],
dataLabels: {
formatter: (val, { seriesIndex, w }) => w.config.series[seriesIndex] // <--- HERE
}
};
let chart = new ApexCharts(document.querySelector('#chart'), options);
chart.render();
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<div id="chart"></div>

How to set color of Chart.js tick label based on tick value - negative values red

I would like to set the color of y-axis tick labels in Chart.js bar and line charts based on the numeric label value. Specifically, I'd like negative values to be rendered red. Additionally rather than displaying "-1", "-2", etc., I'd like to override to display "(1)", "(2)", etc.
I've seen examples for changing tick labels based on index / position, but not conditionally based on the label value. Thanks in advance for any guidance.
You can define the scriptable option scales.x.ticks.color as an array of colors that depend on the corresponding data value each. The following definition for example shows red tick labels for every bar of a value less than 10.
scales: {
x: {
ticks: {
color: data.map(v => v < 10 ? 'red' : undefined)
}
}
}
For further information, consult Tick Configuration from the Chart.js documentation.
Please take a look at below runnable code and see how it works.
const data = [4, 12, 5, 13, 15, 8];
new Chart('myChart', {
type: 'bar',
data: {
labels: ['A', 'B', 'C', 'D', 'E', 'F'],
datasets: [{
label: 'Dataset',
data: data,
}]
},
options: {
responsive: false,
scales: {
x: {
ticks: {
color: data.map(v => v < 10 ? 'red' : undefined)
}
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<canvas id="myChart" height="180"></canvas>

How to set max number of items in a list?

I have containers which user can tab to choose their interests.
Upon tabbing, container color changes to show users they have chosen this option, and the interest is added to a list (backend).
Currently, everything is functioning well, but I don't want users to choose more than 9 interests bcos those interests will probably not be as important anymore.
Anyone has any idea how can I limit the max number of items in my list? As well as not allowing users to tab on the 10th container, or maybe at any point of time only 9 containers will change color.
Any guidance is much appreciated! Stay safe all! :D
Below is the code where the interests are added or removed.
var chosenInterests = chosenSportsInterests +
chosenEntertainmentInterests +
chosenCharacterInterests +
chosenArtsInterests +
chosenWellnessInterests +
chosenLanguageInterests;
if (widget.viewInterest.isChosen) {
Widget build(BuildContext context) {
Container container = Container(
height: MediaQuery.of(context).size.height * 0.03,
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width * 0.024,
vertical: MediaQuery.of(context).size.height * 0.003),
// padding: EdgeInsets.fromLTRB(12, 6, 12, 6),
margin: EdgeInsets.fromLTRB(4.5, 3, 6, 3),
decoration: BoxDecoration(
color: widget.viewInterest.isChosen && chosenInterests.length < 9
? Colors.yellow[300]
: Color(0xff04072E),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 2,
blurRadius: 1,
offset: Offset(0, 1), // changes position of shadow
),
],
borderRadius: BorderRadius.circular(15),
),
child: Text(
'${widget.viewInterest.title}',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: widget.viewInterest.isChosen && chosenInterests.length < 9
? Colors.black
: Colors.white),
));
if (widget.viewInterest.isChosen && chosenInterests.length < 9) {
chosenSportsInterests.add('${widget.viewInterest.title}');
print(chosenInterests);
} else {
chosenSportsInterests.remove('${widget.viewInterest.title}');
print(chosenInterests);
}
I assume you are using a list and each time your user chooses an interest you add it to that list.
with this thing what you can do is whenever your user choose an interest before adding to the list check that list length and if it was larger than 9 you can show a message instead of adding to list

ChartJS plotting x/y in a line chart

I have a collection of 1000s of x/y points. I would like to plot them on a chart with a line connecting them all. This should be very easy to do but upon reading the docs there is no plot(x,y) type function. I am noticing the following:
It looks like a label has to be created for every x value. I may not know the x values at the time of the charts creation
I have huge numbers with many decimal places. I assume this will mean that most x values end up between labels.
Is there a way to plot the points without having a circular plot point shape? Basically a smooth line running all the way from the left to the right that is created based on the x/y data?
Here is some example data so you get the idea:
data: [
{x: 21345.67890, y: 40},
{x: 22783.12345, y: 43},
{x: 27900.00012, y: 80},
// many more plot points
],
Am I missing something obvious? Is there a quick example someone could whip up to show me how this works?
It looks like a label has to be created for every x value. I may not know the x values at the time of the charts creation
I am not sure how your data arises, but aking into consideration the information provided, you should create an object containing all of your data points and use the object within the chart function.
To provide a solution for this part we would need more input about how your data is built.
I have huge numbers with many decimal places. I assume this will mean that most x values end up between labels.
Well, this is more or less the spirit of a line chart. Depending on the data's value you should just define your axes properly to get a understandable visualization of your data.
Is there a way to plot the points without having a circular plot point shape? Basically a smooth line running all the way from the left to the right that is created based on the x/y data?
Chart.JS comes with a lot of options to play with. E.g. you could use pointStyle or pointRadius properties to change the points to your needs.
I attached an example for you to adapt as needed. As you can see the lines are smoothly visualized. The example uses multiple chart types in one. You can just remove the bar part.
For further reference check out the official documentation, especially the line-chart part: https://www.chartjs.org/docs/latest/charts/line.html
var optionsMulti = {
chart: {
height: 280,
width: 375,
type: 'line',
stacked: false,
toolbar: {
show: false
},
plotOptions: {
bar: {
horizontal: false,
columnWidth: '55%',
endingShape: 'rounded'
},
},
},
series: [{
name: 'Goals scored',
data: [2, 4, 5, 1, 1, 3, 3, 2, 4, 5, 1, 3]
}, {
name: 'Goals Conceded',
data: [1, 1, 3, 4, 2, 2, 3, 2, 1, 2, 5, 3]
}, {
name: 'Points gained',
type: 'column',
data: [3, 3, 3, 0, 0, 3, 0, 0, 3, 3, 0, 1]
}],
stroke: {
width: [4, 4, 4],
curve: 'smooth'
},
labels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
xaxis: {
type: 'category',
line: {
show: false
},
},
yaxis: {
min: 0,
max: 6,
tickamount: 6,
labels: {
show: false
},
line: {
show: false
},
},
};
var chartMulti = new ApexCharts(
document.querySelector("#chartMulti"),
optionsMulti
);
chartMulti.render();
<html>
<body>
<div id="chartMulti"></div>
</body>
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
</html>

Show data on Chart instead of tooltip

Using Google pie charts
Fiddle
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 20],
['Eat', 2],
['Commute', 2],
['Watch TV', 2]
]);
How can I get the 'Hours per Day' to show in the chart itself. Now it is showing in the tooltip mouseover. For example mouseover on Eat will show 2. When I save/print the chart I can't get these items. How to show this on the chart?
the pieSliceText configuration option allows you to change what appears on each slice
to get the value of the row, use...
pieSliceText: 'value'
also, if the chart isn't big enough, it will omit the label
there are several ways to size the chart
you can style the div container,
or set the height and width in the options
also, google recommends waiting on the chart's 'ready' event,
before calling any methods, including getImageURI
see following working snippet...
google.charts.load('current', {
callback: function () {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 20],
['Eat', 2],
['Commute', 2],
['Watch TV', 2]
]);
var options = {
height: 400,
legend: {
position: 'labeled',
textStyle: {
color: 'blue'
}
},
pieSliceText: 'value',
title: 'My Daily Activities',
width: 800
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
google.visualization.events.addListener(chart, 'ready', function () {
document.getElementById('image_div').innerHTML = '<img alt="Chart" src="' + chart.getImageURI() + '">';
});
chart.draw(data, options);
},
packages:['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
<div id="image_div"></div>