give a html+js single file example to show [Redacted Person] with line chart together.…
- User
give a html+js single file example to show [Redacted Person] with line chart together. Use CDN
Assistant
html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Combined Pie and Line Chart</title> <script src="https://code.highcharts.com/highcharts.js"></script> </head> <body> <div id="container" style="width: 600px; height: 400px;"></div> <script> document.addEventListener('DOMContentLoaded', function () { Highcharts.chart('container', { title: { text: 'Combined Pie and Line Chart' }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, yAxis: [{ // Primary yAxis for line chart title: { text: 'Line Data' } }, { // Secondary yAxis for pie chart (hidden) title: { text: null }, labels: { enabled: false }, opposite: true, // Place on the right side visible: false // Hide the axis itself }], series: [{ type: 'line', name: 'Line Series', data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] }, { type: 'pie', name: 'Pie Series', data: [{ name: 'Category A', y: 45, color: 'blue' // Customize individual slice color }, { name: 'Category B', y: 25, color: 'green' }, { name: 'Category C', y: 30, color: 'orange' }], center: [500, 150], // Adjust center position as needed size: 150, // Adjust pie chart size showInLegend: false, // Optionally hide pie series from legend dataLabels: { enabled: true, format: '{point.name}: {point.percentage:.1f}%' }, yAxis: 1 // Connect pie chart to secondary yAxis }] }); }); </script> </body> </html>- User
Пусть в пайчарте выводится для примера 10 стран и их население, а на line chart - рождаемость по годам. Сделай чтобы line чарт обновлялся когда я выбираю сектор пайчарта (или заголовок если сектор маленький)
Assistant
- User
Почему-то когда я выбираю какую-то страну, а потом Китай, линейный график не обновляется. Можешь исправить?
Assistant
You are absolutely right! There was a logic error in the previous code. The problem was in how the
updateLineChartfunction was accessing the birth rate data. It was incorrectly using the index of the pie slice instead of the country name to look up the data.Here's the corrected code:
javascriptdocument.addEventListener('DOMContentLoaded', function () { // ... (countries data remains the same) // ... (pieData generation remains the same) const chart = Highcharts.chart('container', { // ... (chart options remain the same) }); function updateLineChart(countryName) { const birthRateData = countries[countryName].birthRate; // Correctly access birthRate by country name chart.get('birthRateLine').update({ data: birthRateData, name: countryName + ' Birth Rate' // Update the series name for clarity }); } // ... (rest of the code remains the same) });- User
Не исправилось или исправилось, но не работает с другой страной, например, с Индией. Проверь ещё раз. Приводи полный код.
Assistant
- User
Нет, если я повторно выбираю первую выбранную страну, график рождаемости не обновляется. Исправь и приведи полный код.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.