### Mosaic Chart Quick Start Source: https://github.com/visactor/vchart/blob/develop/docs/assets/guide/en/tutorial_docs/Chart_Types/Mosaic.md This example demonstrates the basic setup for a Mosaic chart, including data binding and essential configuration. It shows how to register the chart type and render it. Note the conditional import/registration logic for business contexts versus standalone examples. ```javascript /** --Add the following code when using in business context-- */ // When using in business context, please additionally import registerMosaicChart and execute // import { registerMosaicChart } from '@visactor/vchart'; // registerMosaicChart(); /** --Add the above code when using in business context-- */ /** --Delete the following code when using in business context-- */ VCHART_MODULE.registerMosaicChart(); /** --Delete the above code when using in business context-- */ const spec = { type: 'mosaic', data: [ { id: 'barData', values: [ { State: 'WY', Age: 'Under 5 Years', Population: 25635 }, { State: 'WY', Age: '5 to 13 Years', Population: 1890 }, { State: 'WY', Age: '14 to 17 Years', Population: 9314 }, { State: 'DC', Age: 'Under 5 Years', Population: 30352 }, { State: 'DC', Age: '5 to 13 Years', Population: 20439 }, { State: 'DC', Age: '14 to 17 Years', Population: 10225 }, { State: 'VT', Age: 'Under 5 Years', Population: 38253 }, { State: 'VT', Age: '5 to 13 Years', Population: 42538 }, { State: 'VT', Age: '14 to 17 Years', Population: 15757 }, { State: 'ND', Age: 'Under 5 Years', Population: 51896 }, { State: 'ND', Age: '5 to 13 Years', Population: 67358 }, { State: 'ND', Age: '14 to 17 Years', Population: 18794 }, { State: 'AK', Age: 'Under 5 Years', Population: 72083 }, { State: 'AK', Age: '5 to 13 Years', Population: 85640 }, { State: 'AK', Age: '14 to 17 Years', Population: 22153 } ] } ], label: [ { visible: true, position: 'bottom', style: { fill: '#333' }, filterByGroup: { field: 'State', type: 'min' }, overlap: false, formatMethod: (value, datum, ctx) => { return datum['State']; } }, { visible: true, position: 'top', style: { fill: '#333' }, filterByGroup: { field: 'State', type: 'max' }, overlap: false, formatMethod: (value, datum, ctx) => { return `${datum['__VCHART_STACK_END']} ( ${( (datum['__VCHART_MOSAIC_CAT_END_PERCENT'] - datum['__VCHART_MOSAIC_CAT_START_PERCENT']) * 100 ).toFixed(0)}% )`; } }, { visible: true, position: 'center', smartInvert: true } ], xField: 'State', yField: 'Population', seriesField: 'Age', percent: true, legends: { visible: true }, axes: [ { orient: 'left', label: { formatMethod: val => { return `${(val * 100).toFixed(2)}%`; } } } // { // orient: 'bottom', // label: { // visible: false // } // } ] }; const vchart = new VChart(spec, { dom: CONTAINER_ID }); vchart.renderSync(); // Just for the convenience of console debugging, DO NOT COPY! window['vchart'] = vchart; ``` -------------------------------- ### Install Rush for Development Source: https://github.com/visactor/vchart/blob/develop/README.md Before starting development, install the @microsoft/rush package globally. This tool is used for managing the monorepo. ```bash $ npm i --global @microsoft/rush ``` -------------------------------- ### Quick Start Word Cloud Chart Source: https://github.com/visactor/vchart/blob/develop/docs/assets/guide/en/tutorial_docs/Chart_Types/WordCloud.md This example demonstrates the basic configuration for creating a word cloud chart. It requires specifying the chart type, data source, and mapping fields for text and size. ```javascript const response = await fetch('https://lf9-dp-fe-tos.byteorg.com/obj/bit-cloud/data-wordcloud.json'); const dataWordCloud = await response.json(); const spec = { type: 'wordCloud', nameField: 'challenge_name', valueField: 'sum_count', seriesField: 'challenge_name', data: { name: 'baseData', values: dataWordWordCloud } }; const vchart = new VChart(spec, { dom: CONTAINER_ID }); vchart.renderSync(); // 只为了方便控制台调试用,不要拷贝 window['vchart'] = vchart; ``` -------------------------------- ### Quick Start: 3D Bar Chart Example Source: https://github.com/visactor/vchart/blob/develop/docs/assets/guide/en/tutorial_docs/Chart_Types/3d_Bar.md This example demonstrates how to initialize and render a basic 3D bar chart. It includes data, field mappings, and essential 3D view enablement. Ensure the VChart library is included and a container element with the ID 'CONTAINER_ID' is present. ```javascript const spec = { type: 'bar3d', data: [ { id: 'barData', values: [ { month: 'Monday', sales: 22 }, { month: 'Tuesday', sales: 13 }, { month: 'Wednesday', sales: 25 }, { month: 'Thursday', sales: 29 }, { month: 'Friday', sales: 38 } ] } ], xField: 'month', yField: 'sales', bar3d: { style: { length: 20, z: -20 }, state: { selected: { stroke: '#000', strokeWidth: 1 } } }, axes: [ { orient: 'bottom', type: 'band', tick: { tickSize: 20 }, mode: '3d' }, { orient: 'left', type: 'linear', tick: { tickSize: 20 }, mode: '3d' } ] }; const vchart = new VChart(spec, { dom: CONTAINER_ID, disableDirtyBounds: true, options3d: { enable: true } }); vchart.renderSync(); ``` -------------------------------- ### Sequence Chart with Tooltip Configuration Example Source: https://github.com/visactor/vchart/blob/develop/docs/assets/guide/zh/tutorial_docs/Chart_Types/Sequence.md This example demonstrates a sequence chart with detailed tooltip configurations for bar series, including custom start and end times, and values. It also shows tooltip setup for dot series with event information. ```javascript const spec = { type: 'sequence', appendPadding: { left: 80, right: 80 }, series: [ { type: 'bar', barTitle: 'register', dataId: 'register', xField: 'start_time', x2Field: 'end_time', yField: 'value', animation: false, label: { style: { visible: false, fill: 'black' } }, height: 40, padding: 10, tooltip: { visible: true, mark: { title: { key: 'bar info', value: 'bar info' }, content: [ { key: 'start_time', value: datum => datum['start_time'] }, { key: 'start_time_stamp', hasShape: false, value: datum => datum['start_time'] }, { key: 'end_time', value: datum => datum['end_time'] }, { key: 'end_time_stamp', hasShape: false, value: datum => datum['end_time'] }, { key: 'value', value: datum => datum['value'] } ] } } }, { type: 'bar', barTitle: 'im', dataId: 'im', xField: 'start_time', x2Field: 'end_time', yField: 'value', animation: false, height: 40, padding: 10, tooltip: { visible: true, mark: { title: { key: 'bar in do', value: 'bar info' }, content: [ { key: 'start_time', value: datum => datum['start_time'] }, { key: 'start_time_stamp', hasShape: false, value: datum => datum['start_time'] }, { key: 'end_time', value: datum => datum['end_time'] }, { key: 'end_time_stamp', hasShape: false, value: datum => datum['end_time'] }, { key: 'value', value: datum => datum['value'] } ] } } }, { type: 'bar', barTitle: 'comment', dataId: 'comment', xField: 'start_time', x2Field: 'end_time', yField: 'value', animation: false, height: 40, padding: 10, tooltip: { visible: true, mark: { title: { key: 'bar info', value: 'bar info' }, content: [ { key: 'start_time', value: datum => datum['start_time'] }, { key: 'start_time_stamp', hasShape: false, value: datum => datum['start_time'] }, { key: 'end_time', value: datum => datum['end_time'] }, { key: 'end_time_stamp', hasShape: false, value: datum => datum['end_time'] }, { key: 'value', value: datum => datum['value'] } ] } } }, { type: 'dot', dataId: 'dataDotSeries', xField: 'event_time', yField: 'id', seriesGroupField: 'type', titleField: 'type', subTitleField: 'id', dotTypeField: 'action_type', highLightSeriesGroup: 'IP', clipHeight: 1000, title: { style: { fill: 'rgba(46, 47, 50)' } }, subTitle: { style: { fill: 'rgba(46, 47, 50)', dy: 7 } }, symbol: { style: { dx: -20 } }, tooltip: { mark: { title: { key: 'event info', value: 'event info' }, content: [ { hasShape: true, shapeType: 'square', key: datum => datum['type'], value: datum => datum['id'] }, { hasShape: false, key: 'event_time_stamp', value: datum => datum['event_time'] }, { hasShape: true, shapeType: 'square', key: 'action_type', value: datum => datum['action_type'] }, { hasShape: true, shapeType: 'square', ``` -------------------------------- ### Create Example Configuration File Source: https://github.com/visactor/vchart/blob/develop/skills/vchart-development-assistant/references/SCRIPTS_TROUBLESHOOTING.md Provides a sample `config.js` structure for the `generate_diagnosis_html.py` script. Ensure it includes `problemReview`, `diagnosis`, and `solutions` objects. ```bash cat > config.js << 'EOF' const problemReview = { specCode: "const spec = { type: 'bar', data: { values: [] } };" }; const diagnosis = { problem: "图表显示问题", cause: "配置项错误" }; const solutions = [ { title: "修复方案", description: "修改配置", specCode: "const spec = { type: 'bar', data: { values: [{x:1,y:2}] } };" } ]; EOF ``` -------------------------------- ### Start React Development Server (Specific Directory) Source: https://github.com/visactor/vchart/blob/develop/packages/react-vchart/README.md Navigate to the package directory and start the React development server using rushx. ```bash cd packages/react-vchart $ rushx start ``` -------------------------------- ### Pie Chart with Smooth Label Lines Source: https://github.com/visactor/vchart/blob/develop/docs/assets/examples/en/pie-chart/smooth-label-line.md Configure the `label.line.smooth` property to `true` to enable smooth curves for label guide lines. This example also shows basic pie chart setup with data, radius, colors, legends, and tooltips. ```javascript const spec = { type: 'pie', data: [ { name: 'data1', values: [ { value: 348, name: '中介渠道: 34.8%' }, { value: 152, name: '会员: 15.2%' }, { value: 500, name: '散客: 50%' } ] } ], valueField: 'value', categoryField: 'name', outerRadius: 0.8, innerRadius: 0.5, color: ['#87DBDD', '#FF8406', '#468DFF'], pie: { state: { hover: { outerRadius: 0.85, stroke: '#000', lineWidth: 1 }, selected: { outerRadius: 0.85, stroke: '#000', lineWidth: 1 } } }, legends: { visible: true, orient: 'right', title: { visible: false }, item: { visible: true } }, tooltip: { transitionDuration: 0 }, label: { visible: true, pickable: false, line: { smooth: true, style: { lineWidth: 2 } } } }; const vchart = new VChart(spec, { dom: CONTAINER_ID }); vchart.renderSync(); // Just for the convenience of console debugging, DO NOT COPY! window['vchart'] = vchart; ``` -------------------------------- ### VChart Initialization and Full Example Source: https://github.com/visactor/vchart/blob/develop/skills/vchart-development-assistant/references/api/layout-api.md A complete HTML example demonstrating VChart initialization, rendering, and interactive resizing. It includes buttons to resize the chart to specific dimensions or fit its container, and uses ResizeObserver for responsive behavior. ```html