You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A reusable charting library for Factorio 2.0+ mods. Provides line graphs and stacked bar charts rendered on hidden surfaces, viewable through GUI camera widgets.
Features
Line Graphs: Multi-series time series data with auto-scaling Y-axis
Stacked Bar Charts: Phase breakdown visualization with optional hatched phases
Interactive Charts: Hit testing, hover highlights, tooltips, overlay buttons
Time Series: Multi-resolution cascading aggregation (like RRDtool)
Surface Management: Automatic chunk allocation and cleanup
Color Palettes: 12 distinct colors for series differentiation
localcharts=require("__factorio-charts__.charts")
-- Initialize (call once in on_init)localsurface_data=charts.surface.create("my-analytics")
-- Allocate a chunk for renderinglocalchunk=charts.surface.allocate_chunk(surface_data)
-- Render a line graphlocalordered_sums, line_ids=charts.render.line_graph(surface_data.surface, chunk, {
data=ring_buffer, -- Array of {[series_name]: value}index=current_index, -- Current position in ring bufferlength=buffer_length, -- Ring buffer capacitycounts=sample_counts, -- {[series_name]: count}sum=series_sums, -- {[series_name]: total}y_range= {0, 100}, -- Optional fixed range (nil for auto-scale)label_format="percent", -- "percent", "time", or function(value) -> stringselected_series=nil, -- Filter: nil=all, {[name]: false}=hidettl=360, -- Render lifetime in ticks
})
-- Render a stacked bar chartlocalline_ids=charts.render.stacked_bars(surface_data.surface, chunk, {
deliveries=delivery_data, -- Array of phase timing objectsphase_colors= { -- Color per phaseloading= {r=0, g=1, b=0},
travel= {r=0, g=0, b=1},
},
phase_order= {"loading", "travel"}, -- Stack order (bottom to top)ttl=360,
})
-- Free chunk when donecharts.surface.free_chunk(surface_data, chunk)
Displaying Charts in GUI
-- Calculate camera parameters for resolution-independent displaylocalcamera=charts.surface.get_camera_params(chunk, {
widget_width=900,
widget_height=700,
})
-- Create camera widgetlocalcamera_widget=parent.add{
type="camera",
position=camera.position,
surface_index=surface_data.surface.index,
zoom=camera.zoom,
}