看起来您正在寻找一个 javascript 解决方案...但是您的问题被标记为 jfreechart ...所以这里是 jfreechart 代码:(...如果是 webapp,您需要提供图像,例如通过休息服务)
import java.awt.*;
import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.data.category.*;
import org.jfree.ui.*;
public class StackedAndLevelChart extends ApplicationFrame {
public StackedAndLevelChart(final String title) {
super(title);
final JFreeChart chart = constructChart();
final ChartPanel panel = new ChartPanel(chart);
setContentPane(panel);
}
JFreeChart constructChart() {
DefaultCategoryDataset barDS = new DefaultCategoryDataset();
Object [][] vals = {
{"Function", "Min", "Max"},
{"functionA", 0, 150},
{"functionB", 11, 100},
{"functionC", 20, 150},
{"functionD", 5, 7},
{"functionE", 0, 22},
{"functionF", 23, 55}
};
for (int i=1; i<vals.length; i++) {
barDS.addValue((Number)vals[i][1], (String)vals[0][1], (String)vals[i][0]);
barDS.addValue((Number)vals[i][2], (String)vals[0][2], (String)vals[i][0]);
}
JFreeChart chart = ChartFactory.createStackedBarChart(
"Min/Max demo", // chart title
null, // domain axis label
"duration [ms]", // range axis label
barDS, // data
PlotOrientation.HORIZONTAL, // the plot orientation
true, // legend
true, // tooltips
false // urls
);
DefaultCategoryDataset levelDS = new DefaultCategoryDataset();
double [] avg = { 0, 48, 20, 70, 5, 10, 45 };
for (int i=1; i<avg.length; i++) {
levelDS.addValue(avg[i], "avg", (String)vals[i][0]);
}
CategoryPlot plot = chart.getCategoryPlot();
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
chart.getLegend().setPosition(RectangleEdge.RIGHT);
CategoryItemRenderer renderer1 = plot.getRenderer();
renderer1.setSeriesPaint(0, Color.BLUE);
renderer1.setSeriesPaint(1, Color.RED);
CategoryItemRenderer renderer2 = new LevelRenderer();
plot.setDataset(1, levelDS);
plot.setRenderer(1, renderer2);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
renderer2.setSeriesPaint(0, Color.BLACK);
renderer2.setSeriesStroke(0, new BasicStroke(5.0f));
return chart;
}
public static void main(String[] args) {
StackedAndLevelChart demo = new StackedAndLevelChart("");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}