问题
My question is a combination of these old questions.
how to start draw line from X - Y axis at o in JFreeChart ChartFactory.createLineChart
How to draw line chart using jfreechart from top to bottom?
I'm working in a project and need to implement a feature to create a line chart using JFreechart. Each line chart must satisfy all 2 conditions.
- Each line must start from (0,0) coordinate (or at least look like that)
- X-axis must be string-based. For example: "30-Oct-2017", "04-Dec-2017", etc.
EDITED: ok I decided to implement TimeSeriesCollection as the chart's dataset. This is what I have so far.
private String makeLineChart(Map<Date, List<Map<String, Object>>> entryMap, String type, PlotOrientation chartOrientation)
{
String newline = System.getProperty("line.separator");
int maxNumberOfResponses = 0;
JFreeChart chart;
List<Date> listEntryMapKeys = new ArrayList<Date>(entryMap.keySet());
switch (type)
{
case "line":
default:
DefaultCategoryDataset resultLine = new DefaultCategoryDataset();
TimeSeriesCollection dataset = new TimeSeriesCollection();
List<TimeSeries> listOfSeries = new ArrayList<TimeSeries>();
List<String> titles = new ArrayList<String>();
Date startSurveyDate = listEntryMapKeys.get(0);
Date endSurveyDate = listEntryMapKeys.get(listEntryMapKeys.size() - 1);
StringBuilder sblog = new StringBuilder();
String logtitle = "";
String logfilename = String.format("Debug_makeLineChart_SurveyAnalyticsController");
for (int i = 0; i < listEntryMapKeys.size(); i++)
{
Date d = listEntryMapKeys.get(i);
Date pd = (i >= 1) ? listEntryMapKeys.get(i - 1) : d;
String date = DateTimeConverter.ParseDateToString(d, Chart.CHART_DATE_FORMAT);//for either x or y column
String prevdate = DateTimeConverter.ParseDateToString(pd, Chart.CHART_DATE_FORMAT);
List<Map<String, Object>> listOfStatistics = entryMap.get(d);
Map<String, Integer> mapOfStatisticsByQuestionResult = new HashMap<String, Integer>();
for (Map<String, Object> subEntity : listOfStatistics)
{
String title = subEntity.get("qrtitle").toString().trim();
if (!mapOfStatisticsByQuestionResult.containsKey(title))
{
mapOfStatisticsByQuestionResult.put(title, 1);
}
else
{
int count = mapOfStatisticsByQuestionResult.get(title) + 1;
mapOfStatisticsByQuestionResult.put(title, count);
}
}
sblog.append("Debugging date ");
sblog.append((new SimpleDateFormat("dd-MM-yyyy")).format(d));
sblog.append("...");
sblog.append(newline);
sblog.append("Value of mapOfStatisticsByQuestionResult:");
sblog.append(StringConverter.ParseObjectToJson(mapOfStatisticsByQuestionResult));
sblog.append(newline);
for (int k = 0; k < 5; k++)
{
sblog.append("-");
}
sblog.append(newline);
for (String result : mapOfStatisticsByQuestionResult.keySet())
{
int count = mapOfStatisticsByQuestionResult.get(result);//should be the sum of current & previous
TimeSeries series = new TimeSeries(result);
sblog.append(newline);
sblog.append("Searching for item with key is ");
sblog.append(result);
sblog.append(" in listOfSeries (");
sblog.append(listOfSeries.size());
sblog.append(" item(s))...");
sblog.append(newline);
TimeSeries currentSeries = listOfSeries.stream().filter(x -> x.getKey() != null && x.getKey().toString().trim().equalsIgnoreCase(result)).findFirst().orElse(null);
sblog.append(currentSeries != null ? "NOT FOUND" : "FOUND");
sblog.append(newline);
int indexOfSeries = IntStream.range(0, listOfSeries.size()).
filter(x -> listOfSeries.get(x).getKey() != null && listOfSeries.get(x).getKey().toString().trim().equalsIgnoreCase(result)).
findFirst().orElse(-1);
sblog.append("Index of the item: ");
sblog.append(indexOfSeries);
sblog.append(newline);
sblog.append(newline);
if (indexOfSeries >= 0)
{
series = listOfSeries.get(indexOfSeries);
}
if (!titles.contains(date))
{
titles.add(date);
}
if (i >= 1)
{
if (chartOrientation == PlotOrientation.HORIZONTAL)
{
try
{
int current = resultLine.getValue(result, prevdate).intValue();
int sum = current + count;
resultLine.addValue(sum, result, date);
series.addOrUpdate(new Day(d), count); //series.addOrUpdate(new Day(d), sum);
if (sum > maxNumberOfResponses)
{
maxNumberOfResponses = sum;
}
}
catch (Exception ex)
{
//resultLine.addValue(0, result, "0");
resultLine.addValue(count, result, date);
series.addOrUpdate(new Day(d), count);
if (count > maxNumberOfResponses)
{
maxNumberOfResponses = count;
}
}
}
else
{
try
{
int current = resultLine.getValue(prevdate, result).intValue();
int sum = current + count;
resultLine.addValue(sum, date, result);
series.addOrUpdate(new Day(d), count); //series.addOrUpdate(new Day(d), sum);
if (sum > maxNumberOfResponses)
{
maxNumberOfResponses = sum;
}
}
catch (Exception ex)
{
//resultLine.addValue(0, result, "0");
resultLine.addValue(count, date, result);
series.addOrUpdate(new Day(d), count);
if (count > maxNumberOfResponses)
{
maxNumberOfResponses = count;
}
}
}
}
else
{
//resultLine.addValue(0, result, "0");
if (chartOrientation == PlotOrientation.HORIZONTAL)
{
resultLine.addValue(count, result, date);
series.addOrUpdate(new Day(d), count);
}
else
{
resultLine.addValue(count, date, result);
series.addOrUpdate(new Day(d), count);
}
if (count > maxNumberOfResponses)
{
maxNumberOfResponses = count;
}
}
indexOfSeries = IntStream.range(0, listOfSeries.size()).
filter(x -> listOfSeries.get(x).getKey() != null && listOfSeries.get(x).getKey().toString().trim().equalsIgnoreCase(result)).
findFirst().orElse(-1);//suspicious of giving wrong result
sblog.append("Index of the item (before adding new item): ");
sblog.append(indexOfSeries);
sblog.append(newline);
if (indexOfSeries >= 0)
{
listOfSeries.set(indexOfSeries, series);
}
else
{
listOfSeries.add(series);
}
}
}
sblog.append(newline);
for (int k = 0; k < 20; k++)
{
sblog.append("-");
}
sblog.append(newline);
sblog.append("Debugging listOfSeries (");
sblog.append(listOfSeries.size());
sblog.append(" item(s))...");
sblog.append(newline);
for (int k = 0; k < 10; k++)
{
sblog.append("-");
}
SimpleDateFormat dateformatter = new SimpleDateFormat("dd/MM/yyyy");
int index = 0;
for (TimeSeries series : listOfSeries)
{
index++;
if (series.getTimePeriod(0).getStart().after(startSurveyDate))
{
series.addOrUpdate(new Day(startSurveyDate), 0);
}
else if (series.getValue(0).doubleValue() > 0)
{
series.addOrUpdate(new Day(DateTimeConverter.AddOrSubtractDay(startSurveyDate, -1)), 0);
}
if (series.getTimePeriod(series.getItemCount() - 1).getEnd().before(endSurveyDate))
{
series.addOrUpdate(new Day(endSurveyDate), 0);
}
else if (series.getValue(series.getItemCount() - 1).doubleValue() > 0)
{
series.addOrUpdate(new Day(DateTimeConverter.AddOrSubtractDay(endSurveyDate, 1)), 0);
}
dataset.addSeries(series);
sblog.append(newline);
sblog.append("Debugging series ");
sblog.append(index);
sblog.append("...");
sblog.append(newline);
sblog.append("Title: ");
sblog.append("\"");
sblog.append(series.getKey().toString());
sblog.append("\"");
sblog.append(newline);
for (int i = 0; i < series.getItemCount(); i++)
{
sblog.append("Time period: ");
sblog.append(dateformatter.format(series.getTimePeriod(i).getStart()));
sblog.append(" - ");
sblog.append(dateformatter.format(series.getTimePeriod(i).getEnd()));
sblog.append(newline);
sblog.append("Value: ");
sblog.append("\"");
sblog.append(series.getValue(series.getTimePeriod(i)));
sblog.append("\"");
sblog.append(" ");
sblog.append("(");
sblog.append(series.getValue(i));
sblog.append(")");
sblog.append(newline);
}
sblog.append(newline);
sblog.append(newline);
}
sblog.append(newline);
String logcontent = sblog.toString();
DebugWriter.WriteLogToFile(logtitle, logcontent, logfilename, false);
if (chartOrientation == PlotOrientation.HORIZONTAL)
{
chart = ChartFactory.createXYLineChart("", "Number of responses", "Number of responses", dataset, PlotOrientation.HORIZONTAL, true, true, false);
}
else
{
chart = ChartFactory.createXYLineChart("", "Survey date", "Number of responses", dataset, PlotOrientation.VERTICAL, true, true, false);
}
XYPlot plot = (XYPlot) chart.getPlot();
DateAxis dateAxis = new DateAxis("Survey dates");
dateAxis.setLabelFont(new Font(Font.SERIF, Font.BOLD, 20));
dateAxis.setDateFormatOverride(new SimpleDateFormat(Chart.CHART_DATE_FORMAT));
if (chartOrientation == PlotOrientation.HORIZONTAL)
{
dateAxis.setInverted(true);
}
dateAxis.setMinimumDate(startSurveyDate);
dateAxis.setMaximumDate(endSurveyDate);
dateAxis.setLowerBound(0);
dateAxis.setAutoRange(true);
plot.setDomainAxis(dateAxis);
NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
numberAxis.setAutoRange(true);
plot.setRangeAxis(numberAxis);
break;
}
String code = UUID.randomUUID().toString().replaceAll("-", "");
String filename = new File(chartDir, code + ".png").getAbsolutePath();
try
{
File tmpdir = new File(chartDir);
if (!tmpdir.exists())
{
tmpdir.mkdirs();
}
if (maxNumberOfResponses < 20)
{
maxNumberOfResponses = chartOrientation == PlotOrientation.HORIZONTAL ? maxNumberOfResponses * 50 : maxNumberOfResponses * 15;
}
else if (maxNumberOfResponses < 50)
{
maxNumberOfResponses = chartOrientation == PlotOrientation.HORIZONTAL ? maxNumberOfResponses * 45 : maxNumberOfResponses * 10;
}
else if (maxNumberOfResponses < 100)
{
maxNumberOfResponses = chartOrientation == PlotOrientation.HORIZONTAL ? maxNumberOfResponses * 40 : maxNumberOfResponses * 5;
}
else
{
maxNumberOfResponses = chartOrientation == PlotOrientation.HORIZONTAL ? maxNumberOfResponses * 30 : maxNumberOfResponses;
}
int sizeRangeAxis = (maxNumberOfResponses >= 1) ? (chartOrientation == PlotOrientation.HORIZONTAL ? 300 + maxNumberOfResponses : 200 + maxNumberOfResponses) : 200 + (entryMap.size() - 1) * 50;
int sizeDomainAxis = chartOrientation == PlotOrientation.HORIZONTAL ? 200 + listEntryMapKeys.size() * 70 : 200 + listEntryMapKeys.size() * 100;
FileOutputStream fos = new FileOutputStream(filename);
if (chartOrientation == PlotOrientation.HORIZONTAL)
{
ChartUtilities.writeChartAsPNG(fos, chart, sizeRangeAxis, sizeDomainAxis);
}
else
{
ChartUtilities.writeChartAsPNG(fos, chart, sizeDomainAxis, sizeRangeAxis);
}
fos.close();
return "/survey-analytics.yo?chart=yes&code=" + code;
}
catch (Exception e)
{
}
return "";
}
This is my sample data.
{
"Wed Aug 09 00:00:00 ICT 2017": [],
"Tue Aug 15 00:00:00 ICT 2017": [],
"Wed Aug 16 00:00:00 ICT 2017": [],
"Fri Aug 25 00:00:00 ICT 2017": [],
"Mon Oct 16 00:00:00 ICT 2017": [{
"qrid": "6a3560a320ca4ae89e6475f81bd439b36a3560a320ca4ae89e6475f81bd439b3.ac432e0f4b1349aa90307dbf4d4a26fa",
"qrtitle": "Iphone 8s plus is better.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "ec11d1f285db4350bad7176db1cb94db"
},
{
"qrid": "6a3560a320ca4ae89e6475f81bd439b36a3560a320ca4ae89e6475f81bd439b3.c114317c90f148a38748afb725ab3081",
"qrtitle": "Iphone 8s plus is better.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "4a97a0bb8bc14c6ba79f1fa7546fb931"
},
{
"qrid": "6a3560a320ca4ae89e6475f81bd439b36a3560a320ca4ae89e6475f81bd439b3.dc5308e8a6bf40b0b9bbb7f036b7539b",
"qrtitle": "Iphone 8s plus is better.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "eaad14795e6847698faa8c6ebba4f60f"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.eb751643f52442fb8565a8f4ef486518",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "e71924f9a8554820a27f891af019ad0c"
},
{
"qrid": "263c99a0687b4628a042f2908cda6c83263c99a0687b4628a042f2908cda6c83.f0d34ce46f4d4312a903363482d03cb7",
"qrtitle": "S9 is better.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "b6fc0300b61647a29754433f87022674"
},
{
"qrid": "263c99a0687b4628a042f2908cda6c83263c99a0687b4628a042f2908cda6c83.f1e0f921a4ec40038d2973cb34e10b00",
"qrtitle": "S9 is better.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "6c06cc1b4ed4460484963e6dcbf44db6"
},
{
"qrid": "6a3560a320ca4ae89e6475f81bd439b36a3560a320ca4ae89e6475f81bd439b3.fd14094cc6b74c3995ce32796510ee14",
"qrtitle": "Iphone 8s plus is better.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "9c536e71e5604a63afdbb8c01bbd8745"
},
{
"qrid": "6a3560a320ca4ae89e6475f81bd439b36a3560a320ca4ae89e6475f81bd439b3.ffef655a26284b539cf39b57249938ab",
"qrtitle": "Iphone 8s plus is better.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "00617cf9d537465aa02795571830100f"
}
],
"Thu Nov 30 00:00:00 ICT 2017": [{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.0f4fdf31a2904c87a588f22f71ddac12",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "2d90d38546e94e94b22190d03609312d"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.12049a8c710743418e2a0b6128599022",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "80e5669fe68d40b7b7bef3d54d1898a7"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.1c3de97497bc462b8193eb0b8218b9f3",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "5b1decddfbd34593aa6f2d8b0e8ca380"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.24d9c0c319d942b89249770429a68dfd",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "b0df84a9bee542a395df215403eacfad"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.2aad5178de414b41af0bbf9d5dda052a",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "798e5cd22888488fa7079fb607343690"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.467e5e10fb684063908b437a16b25ed3",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "69a7290bb366461bb44e911c8a19860a"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.55ca4e24035347f1ba26371bcc08fde0",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "d8915cf7aaa1403c949d5ec396294d76"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.68f62cf3e87c463aa43d503a0b79a998",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "2decfab381fe4f15a7fe2197be9aba6d"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.9000ee0cf4d6434e976bc02a5edeb78a",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "19b17bc0f11f47c1bcbd10bd84bde4c9"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.aee76445534f4594905e0be410b16434",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "938aae681b584e049210d508797fe5c2"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.ffd3a7f602e142e583dd4eb57cab042c",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "b63824a2a8a04422a9c9756ef56992c1"
}
],
"Mon Dec 04 00:00:00 ICT 2017": [{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.1a0632ea078144b2a9063288e937eddb",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "26ab2e3f37f642758e03e8aa5a3f373e"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.385c5c37a9ce499eafa7e7f162e2cdf6",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "1aeb748133f0456785cc87ff33d822d6"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.42874d3e33264d9280239464fefd8dbe",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "dc84b06e3ee64a60b8e1321be470c16a"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.acd93c0cdae3485299912a784dc876bc",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "ef7a00ca3f8c4327b51cffd05cf00c8b"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.d3a5eb0f0b984cc5862d338a7ad48ce8",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "827ee6e3fec0434898e4416b24f166de"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.ef995b200a704919a2cab694216baeb0",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "1480ce38be4046759e0d2db1a83b7c20"
}
],
"Wed Jan 10 00:00:00 ICT 2018": [{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.042a258ddb99439fa51f0882a467b233",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "7dd475e24b8b434895ce732576590bd0"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.2171eace203e469583dedf1ea307f3ff",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "1a56ea09ca6c457f83f9550b68a70e21"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.35311b8ef99e4e9b8128df5b6d6707b1",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "dc163ae914594b9a89bcd1151b3a0adc"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.455dc78a26294a1a815d68d0dc02bdc5",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "a0ab35b7e4b7423ab4fd4b03606f58ba"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.5cbf3a30977c49fcb32ce1e086cd4661",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "01f28aedaed7481289c37effe4045747"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.8429a220b74d40698a1ea39fb46bd5b8",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "60e9c74e81ca4650bd0fdd8e30463c76"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.8feb181aa884455d81a0f631809e4ffa",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "2e529d2b44bc40b7945c2d68b693b057"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.a8333465cb744b7f8fd4df3b11c16382",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "f1717de12d534298bdca50a431c8087f"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.b499dcf69e9646ecbe2495f6153ff14a",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "dd0fce71a8fb4036bbb95211d9688463"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.b84e2b87fa344bf79436532e626c8593",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "457b9af1bb7b4231b4ced51e3e28c7bf"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.d0e85c06b55c4882aa4e1000f8365b56",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "8c8b858e3dab4b2f92b55904f90ee019"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.d38a21324710436fa1b2121a9c12cdbe",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "c6776066d8a64d8dbdff18c822216cbd"
},
{
"qrid": "5d7f9cc459bf4ee8a805c9fccaeabb405d7f9cc459bf4ee8a805c9fccaeabb40.d799b85a988c4955b60318d4e7e361a4",
"qrtitle": "this is the one i like.",
"qid": "269c2de5d3634800a36d64e342b24cba",
"qkind": "ranking",
"srid": "211f1f0977cb4067baca93c13baa4660"
}
]
}
This is what appears on running.
It looks much better than before but there 1 problem still remains. I want to make the lowest bound of the chart (in this case 09-Aug-2017) to move left so the chart series might look like they start from (0,0) coordinate. How can I achieve this?
回答1:
I've finally found the solution. Turns out it's easier than I thought. I added this line
dateAxis.setLowerMargin(0);
below
dateAxis.setLowerBound(0);
and before
dateAxis.setAutoRange(true);
Problem solved.
来源:https://stackoverflow.com/questions/48145295/how-to-create-line-chart-that-starts-from-zero-and-1-axis-must-be-string-based