@@ -114,6 +114,12 @@ export function ChartConfigPanel({ columns, config, onChange, className }: Chart
114114 if ( defaultX ) {
115115 updates . xAxisColumn = defaultX . name ;
116116 needsUpdate = true ;
117+
118+ // Auto-set sort to x-axis ASC if it's a datetime column
119+ if ( isDateTimeType ( defaultX . type ) && ! config . sortByColumn ) {
120+ updates . sortByColumn = defaultX . name ;
121+ updates . sortDirection = "asc" ;
122+ }
117123 }
118124 }
119125
@@ -123,6 +129,18 @@ export function ChartConfigPanel({ columns, config, onChange, className }: Chart
123129 needsUpdate = true ;
124130 }
125131
132+ // Auto-set sort by x-axis ASC if x-axis is datetime and no sort is configured
133+ if (
134+ config . xAxisColumn &&
135+ ! config . sortByColumn &&
136+ ! updates . sortByColumn &&
137+ dateTimeColumns . some ( ( col ) => col . name === config . xAxisColumn )
138+ ) {
139+ updates . sortByColumn = config . xAxisColumn ;
140+ updates . sortDirection = "asc" ;
141+ needsUpdate = true ;
142+ }
143+
126144 if ( needsUpdate ) {
127145 onChange ( { ...config , ...updates } ) ;
128146 }
@@ -252,7 +270,18 @@ export function ChartConfigPanel({ columns, config, onChange, className }: Chart
252270 < ConfigField label = "X-Axis" >
253271 < Select
254272 value = { config . xAxisColumn ?? "" }
255- setValue = { ( value ) => updateConfig ( { xAxisColumn : value || null } ) }
273+ setValue = { ( value ) => {
274+ const updates : Partial < ChartConfiguration > = { xAxisColumn : value || null } ;
275+ // Auto-set sort to x-axis ASC if selecting a datetime column
276+ if ( value ) {
277+ const selectedCol = columns . find ( ( c ) => c . name === value ) ;
278+ if ( selectedCol && isDateTimeType ( selectedCol . type ) ) {
279+ updates . sortByColumn = value ;
280+ updates . sortDirection = "asc" ;
281+ }
282+ }
283+ updateConfig ( updates ) ;
284+ } }
256285 variant = "tertiary/small"
257286 placeholder = "Select column"
258287 items = { xAxisOptions }
0 commit comments