|
Post by metro on Sept 3, 2023 7:35:16 GMT -5
This may be of interest: In May 2003 Alyce proposed a competition as far as I can tell there were 3 entries. I am unable to determine why the dll for alyce's effort does not work. could be a Linux<wine> issue.
I believe ImageMagic can create Charts, never used it though I'd be happy with 10% of your talent Dan. Maybe LB5 & RunBasic will merge one day.
|
|
|
Post by meerkat on Sept 3, 2023 18:07:47 GMT -5
Hi Metro! Good to see you are still around down under..
I always use JS to do pie charts. It grabs code from the web using this script; <script src=""https://d3js.org/d3.v5.min.js""></script> Simply change the code "const data = [" to your names and percent.
I think LB5 may catch up to RB eventually. Lets hope! All this stuff is available in RB.
open "c:/pie.html" for output as #f
print #f,"<!DOCTYPE html> <html> <head> <script src=""https://d3js.org/d3.v5.min.js""></script> </head> <body> <div id=""pie-chart""></div>
<script> // Sample data for the pie chart const data = [ { label: ""Category A"", value: 30 }, { label: ""Category B"", value: 35 }, { label: ""Category C"", value: 20 }, { label: ""Category D"", value: 10 }, { label: ""Category E"", value: 05 } ];
// Set up the dimensions of the pie chart const width = 300; const height = 300; const radius = Math.min(width, height) / 2;
// Create a color scale const color = d3.scaleOrdinal() .domain(data.map(d => d.label)) .range(d3.schemeCategory10);
// Create a pie layout const pie = d3.pie() .value(d => d.value);
// Create an arc generator const arc = d3.arc() .outerRadius(radius) .innerRadius(0);
// Create the SVG element for the pie chart const svg = d3.select(""#pie-chart"") .append(""svg"") .attr(""width"", width) .attr(""height"", height) .append(""g"") .attr(""transform"", `translate(${width / 2},${height / 2})`);
// Generate the pie chart segments const arcs = svg.selectAll(""arc"") .data(pie(data)) .enter() .append(""g"");
// Draw the pie chart segments arcs.append(""path"") .attr(""d"", arc) .attr(""fill"", d => color(d.data.label));
// Add labels to the pie chart segments arcs.append(""text"") .attr(""transform"", d => `translate(${arc.centroid(d)})`) .attr(""text-anchor"", ""middle"") .text(d => d.data.label);
</script> </body> </html>" close #f end
|
|
|
Post by metro on Sept 3, 2023 19:05:33 GMT -5
Thanks for the tip Dan, Too wet ATM to get to my shed, so sittin at the keyboard for a while. Just realis(z)ed how rusty you get not coding for months
|
|
|
Post by Brandon Parker on Sept 8, 2023 20:08:03 GMT -5
And...so that we can write the HTML to file from LB... CRLF$ = chr$(13);chr$(10)
'Change the path if desired Open "c:/pie.html" For Output As #f
#f "<!DOCTYPE html>";CRLF$;_ "<html>";CRLF$;_ "<head>";CRLF$;_ " <script src=";chr$(34);"https://d3js.org/d3.v5.min.js";chr$(34);"></script>";CRLF$;_ "</head>";CRLF$;_ "<body>";CRLF$;_ " <div id=";chr$(34);"pie-chart";chr$(34);"></div>";CRLF$;_ " ";CRLF$;_ " <script>";CRLF$;_ " // Sample data for the pie chart";CRLF$;_ " const data = [";CRLF$;_ " { label: ";chr$(34);"Category A";chr$(34);", value: 30 },";CRLF$;_ " { label: ";chr$(34);"Category B";chr$(34);", value: 35 },";CRLF$;_ " { label: ";chr$(34);"Category C";chr$(34);", value: 20 },";CRLF$;_ " { label: ";chr$(34);"Category D";chr$(34);", value: 10 },";CRLF$;_ " { label: ";chr$(34);"Category E";chr$(34);", value: 05 }";CRLF$;_ " ];";CRLF$;_ " ";CRLF$;_ " // Set up the dimensions of the pie chart";CRLF$;_ " const width = 300;";CRLF$;_ " const height = 300;";CRLF$;_ " const radius = Math.min(width, height) / 2;";CRLF$;_ " ";CRLF$;_ " // Create a color scale";CRLF$;_ " const color = d3.scaleOrdinal()";CRLF$;_ " .domain(data.map(d => d.label))";CRLF$;_ " .range(d3.schemeCategory10);";CRLF$;_ " ";CRLF$;_ " // Create a pie layout";CRLF$;_ " const pie = d3.pie()";CRLF$;_ " .value(d => d.value);";CRLF$;_ " ";CRLF$;_ " // Create an arc generator";CRLF$;_ " const arc = d3.arc()";CRLF$;_ " .outerRadius(radius)";CRLF$;_ " .innerRadius(0);";CRLF$;_ " ";CRLF$;_ " // Create the SVG element for the pie chart";CRLF$;_ " const svg = d3.select(";chr$(34);"#pie-chart";chr$(34);")";CRLF$;_ " .append(";chr$(34);"svg";chr$(34);")";CRLF$;_ " .attr(";chr$(34);"width";chr$(34);", width)";CRLF$;_ " .attr(";chr$(34);"height";chr$(34);", height)";CRLF$;_ " .append(";chr$(34);"g";chr$(34);")";CRLF$;_ " .attr(";chr$(34);"transform";chr$(34);", `translate(${width / 2},${height / 2})`);";CRLF$;_ " ";CRLF$;_ " // Generate the pie chart segments";CRLF$;_ " const arcs = svg.selectAll(";chr$(34);"arc";chr$(34);")";CRLF$;_ " .data(pie(data))";CRLF$;_ " .enter()";CRLF$;_ " .append(";chr$(34);"g";chr$(34);");";CRLF$;_ " ";CRLF$;_ " // Draw the pie chart segments";CRLF$;_ " arcs.append(";chr$(34);"path";chr$(34);")";CRLF$;_ " .attr(";chr$(34);"d";chr$(34);", arc)";CRLF$;_ " .attr(";chr$(34);"fill";chr$(34);", d => color(d.data.label));";CRLF$;_ " ";CRLF$;_ " // Add labels to the pie chart segments";CRLF$;_ " arcs.append(";chr$(34);"text";chr$(34);")";CRLF$;_ " .attr(";chr$(34);"transform";chr$(34);", d => `translate(${arc.centroid(d)})`)";CRLF$;_ " .attr(";chr$(34);"text-anchor";chr$(34);", ";chr$(34);"middle";chr$(34);")";CRLF$;_ " .text(d => d.data.label);";CRLF$;_ " ";CRLF$;_ " </script>";CRLF$;_ "</body>";CRLF$;_ "</html>"
Close #f End {:0) Brandon Parker
|
|