首页 \ 问答 \ jFreechart将地图绘制到下一个绘图值(jFreechart Map plot to the next plot value)

jFreechart将地图绘制到下一个绘图值(jFreechart Map plot to the next plot value)

我是jfreechart的新手,我无法按顺序绘制值。 我有一系列数字,每个数字超过6个十进制值例如:(5.981412023,2636.51824),从+6.00000000到-6.00000000不等。 这些值取自excel表,它有一个图形(xy散射类型),它看起来与jfreechart创建的不同。 我发现这些值并没有按照我给出的顺序绘制,而是排列和绘制。 例如:如果我给出了像(8,6,2,9,4,7,5)这样的序列,那么该图就会被排列,然后该线看起来就像它所绘制的序列那样(2,4,5,6, 7,8,9)。

有什么方法可以在插入的一系列图中绘制它吗? 抱歉我的英语。

例:

package test;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;

public class PlotTest {
    private XYSeriesCollection dataset;

    public static void main (String[] args) {
        new PlotTest();
    }

    public PlotTest () {
        dataset = new XYSeriesCollection();
        XYSeries data = new XYSeries("data");
        data.add(3, 2); //Point 1
        data.add(1, 1); //Point 2
        data.add(4, 1); //Point 3
        data.add(2, 2); //Point 4
        dataset.addSeries(data);
        showGraph();
    }

    private void showGraph() {
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        final ApplicationFrame frame = new ApplicationFrame("Title");
        frame.setContentPane(chartPanel);
        frame.pack();
        frame.setVisible(true);
    }

    private JFreeChart createChart(final XYDataset dataset) {
        final JFreeChart chart = ChartFactory.createScatterPlot(
            "Title",                  // chart title
            "X",                      // x axis label
            "Y",                      // y axis label
            dataset,                  // data
            PlotOrientation.VERTICAL,
            true,                     // include legend
            true,                     // tooltips
            false                     // urls
        );
        XYPlot plot = (XYPlot) chart.getPlot();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, true);
        plot.setRenderer(renderer);
        return chart;
    }

}

基于上面的例子,我希望程序以1-2-3-4的顺序连接点,这是我将它们添加到我的数据集的顺序。 但是我按照2-4的顺序将它们连接起来,按x值排序。


I am new to jfreechart and i am having trouble plotting the values in sequence. i have series of numbers with each one having more than 6 decimal values example:(5.981412023,2636.51824) and varying from +6.00000000 to -6.00000000. The values are taken from excel sheet and it has a graph(xy scatter type), which doesn't look similar to the one created by jfreechart. I found out that the values are not plotted in the sequence which i gave but its arranged and plotted. example: if i gave the sequence like (8,6,2,9,4,7,5), the plot is arranged and then the line looks like its plotted to this arranged sequence like (2,4,5,6,7,8,9).

Is there any way i can plot it in a sequence of the plots inserted ? sorry about my English.

Example:

package test;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;

public class PlotTest {
    private XYSeriesCollection dataset;

    public static void main (String[] args) {
        new PlotTest();
    }

    public PlotTest () {
        dataset = new XYSeriesCollection();
        XYSeries data = new XYSeries("data");
        data.add(3, 2); //Point 1
        data.add(1, 1); //Point 2
        data.add(4, 1); //Point 3
        data.add(2, 2); //Point 4
        dataset.addSeries(data);
        showGraph();
    }

    private void showGraph() {
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        final ApplicationFrame frame = new ApplicationFrame("Title");
        frame.setContentPane(chartPanel);
        frame.pack();
        frame.setVisible(true);
    }

    private JFreeChart createChart(final XYDataset dataset) {
        final JFreeChart chart = ChartFactory.createScatterPlot(
            "Title",                  // chart title
            "X",                      // x axis label
            "Y",                      // y axis label
            dataset,                  // data
            PlotOrientation.VERTICAL,
            true,                     // include legend
            true,                     // tooltips
            false                     // urls
        );
        XYPlot plot = (XYPlot) chart.getPlot();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, true);
        plot.setRenderer(renderer);
        return chart;
    }

}

Based on the above example, I want the program to connect the dots in order 1-2-3-4, which is the order I added them to my dataset. But I do get them connected in order 2-4-1-3, sorted by x-value.


原文:https://stackoverflow.com/questions/30593813
更新时间:2023-05-07 06:05

最满意答案

您不在两个操作中都设置@company实例变量。 你可以使用before_filter来做,像这样:

before_filter :find_company

def change_settings    
  @vacation_days = current_company.vacation_days
  @illnes_days = current_company.illnes_days
end

def update_settings
  if @company.update(company_params)
    redirect_to account_company_path, notice: t('company.settings_changed')
  else
    render action: 'change_settings'
  end
end

private

  def company_params
    params.require(:company).permit(:vacation_days, :illnes_days)
  end

  def find_company
    @company = current_company
  end

You don't set @company instance variable in both your actions. You can do it using before_filter, like this:

before_filter :find_company

def change_settings    
  @vacation_days = current_company.vacation_days
  @illnes_days = current_company.illnes_days
end

def update_settings
  if @company.update(company_params)
    redirect_to account_company_path, notice: t('company.settings_changed')
  else
    render action: 'change_settings'
  end
end

private

  def company_params
    params.require(:company).permit(:vacation_days, :illnes_days)
  end

  def find_company
    @company = current_company
  end

相关问答

更多
  • fields_for通常用于将params分配给相关模型,因此它对数据结构做出了一些特定的假设。 如果模型中有profile属性,则可以将profile参数作为params [:user]集合的一部分,这将正确分配属性。 您可以通过命名字段来执行此操作: text_field_tag(user[profile], "val") text_field_tag(user[profile][name], "val") fields_for is generally used for assigning p ...
  • 自定义RegistrationsController class RegistrationsController < Devise::RegistrationsController private def sign_up_params params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation) end def account_update_par ...
  • 如果所有这些过滤器都在params的subhash中,你可以迭代而不包括不需要的参数(例如:action rails和:controller rails添加的:controller参数),这将最有效。 一旦你做完了,你就可以做到 (params[:filters] || {}).inject(Student.all) do |scope, (key, value)| scope.where(key => value) end This will work best if all of these fi ...
  • 您不在两个操作中都设置@company实例变量。 你可以使用before_filter来做,像这样: before_filter :find_company def change_settings @vacation_days = current_company.vacation_days @illnes_days = current_company.illnes_days end def update_settings if @company.update(company_para ...
  • 我会建议更好地修复窗体视图,在这里添加这些数字: <%= link_to_add_association "Add another", f, :ads %> <%= f.fields_for :ads do |ff| %> <%= ff.form_group ::remote do |ad| %> <%= ad.label :remote %> * <%= ad.text_field :remote %> <% end %> <%= ...
  • 把这样的东西添加到你的application_controller.rb : before_action :store_ref private def store_ref cookies[:ref] = params[:ref] if params[:ref].present? end 像这样的东西给你的用户创建操作: def create @user = User.new(user_params) @user.ref = cookies[:ref] if @user.save ...
  • 您正在关注一个处理更复杂案例的示例(您将同一个表连接两次)并且您的解决方案比它需要的更复杂: class User has_many :subscriptions has_many :conferances, though: :subscriptions def subscribed_to?(conference) conferances.include?(conference) end def find_subscription(conference) subscr ...
  • 嗯, params是一系列key-value对,来自带有页面请求的浏览器。 对于HTTP GET请求, params在URL中编码。 对于这样的请求: http://www.example.com/?foo=1&bar=cat params[:foo]将是"1"而params[:bar]将是"cat" 。 在HTTP/HTML , params实际上只是一系列key-value对,其中key和value是字符串,但Rails有一个特殊的语法,使params成为哈希内部哈希。 对于这样的请求: http:/ ...
  • params看起来像一个哈希,但它确实不是。 因此,如果您在处理控制器中的传入数据时需要“增加”参数,请创建一个包含params或其成员的新数据结构。 添加: 也许你在寻找 @codes=Code.get_codes @all = [] for c in @codes @all << params["group_#{c.name}"] end params looks like a hash, but it really isn't. So if you need to "augment" p ...
  • 这里有什么问题,你是通过id找到你正在使用find,并且你正在传递applyjobid所以你必须使用find_by_applyjobid 试试这个 def show @jobdetail = Jobdescription.find_by_applyjobid(params[:applyjobid]) end What's wrong here is you are finding by id as you are using find, and you are passing applyjobid ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)