55const lcjs = require ( '@lightningchart/lcjs' )
66
77// Extract required parts from LightningChartJS.
8- const { lightningChart, UILayoutBuilders, UIElementBuilders, emptyFill, UIOrigins, AxisTickStrategies, Themes } = lcjs
8+ const { lightningChart, UILayoutBuilders, UIElementBuilders, emptyFill, UIOrigins, AxisTickStrategies, LegendEntryClickBehaviors , Themes } = lcjs
99
1010const chart = lightningChart ( {
1111 resourcesBaseUrl : new URL ( document . head . baseURI ) . origin + new URL ( document . head . baseURI ) . pathname + 'resources/' ,
1212 } )
1313 . ChartXY ( {
14+ legend : {
15+ title : 'Step options' ,
16+ entries : {
17+ events : {
18+ click : LegendEntryClickBehaviors . focusClicked ,
19+ }
20+ }
21+ } ,
1422 theme : Themes [ new URLSearchParams ( window . location . search ) . get ( 'theme' ) || 'darkGold' ] || undefined ,
1523 } )
1624 . setTitle ( 'Survey Report' )
@@ -19,7 +27,7 @@ const stepSeries = []
1927const addSeries = ( step ) =>
2028 stepSeries . push (
2129 chart
22- . addPointLineAreaSeries ( { dataPattern : 'ProgressiveX' , automaticColorIndex : 0 } )
30+ . addPointLineSeries ( { automaticColorIndex : 0 } )
2331 . setName ( step )
2432 . setVisible ( false )
2533 . setCurvePreprocessing ( { type : 'step' , step } )
@@ -91,7 +99,7 @@ let changedData = []
9199
92100stepSeries . forEach ( ( values , i ) => {
93101 changedData = data . map ( ( changex , index ) => ( { x : index , y : changex . y } ) )
94- values . add ( changedData )
102+ values . appendJSON ( changedData )
95103} )
96104
97105changedData . forEach ( ( _ , index ) => {
@@ -105,39 +113,5 @@ changedData.forEach((_, index) => {
105113} )
106114chart . getDefaultAxisY ( ) . setTitle ( 'Amount / Month' ) . setInterval ( { start : 0 , end : 100 , stopAxisAfter : false } )
107115
108- // Add UI controls for switching between step-mode-options.
109- // NOTE: This is not the focus of the example, and will be better covered elsewhere.
110- const stepControls = chart . addUIElement ( UILayoutBuilders . Column )
111- stepControls . addElement ( UIElementBuilders . TextBox ) . setText ( 'Step options' )
112- const buttonLayout = stepControls . addElement ( UILayoutBuilders . Row )
113- const radioButtons = [ ]
114- let switching = false
115- const addRadioButton = ( series ) => {
116- const checkBox = buttonLayout . addElement ( UIElementBuilders . CheckBox ) . setButtonOnFillStyle ( emptyFill ) . setButtonOffFillStyle ( emptyFill )
117- radioButtons . push ( checkBox )
118- series . attach ( checkBox )
119- checkBox . setOn ( false )
120- // Add radio button logic immediately afterwards so that it is applied after plot.
121- // Attach logic (otherwise plot logic will override this)
122- setTimeout ( ( ) => {
123- checkBox . addEventListener ( 'switch' , ( event ) => {
124- const state = event . state
125- if ( switching || ! state ) {
126- return
127- }
128- // Deactivate other buttons
129- for ( const button of radioButtons ) if ( button !== checkBox ) button . setOn ( false )
130- } )
131- } , 100 )
132- series . addEventListener ( 'visiblechange' , ( e ) => {
133- checkBox . setPointerEvents ( ! e . isVisible )
134- } )
135- }
136- addRadioButton ( stepSeries [ 0 ] )
137- addRadioButton ( stepSeries [ 1 ] )
138- addRadioButton ( stepSeries [ 2 ] )
139- const margin = 10
140- stepControls . setPosition ( { x : 30 , y : 80 } ) . setOrigin ( UIOrigins . CenterBottom ) . setMargin ( margin )
141-
142116// Apply initial selection
143117stepSeries [ 1 ] . setVisible ( true )
0 commit comments